form control content attribute changes (not all) reflected in layout; fixed scrolling on <iframe>, <frame>;

added nsImageControlFrame to handle <input type=image>.
This commit is contained in:
karnaze%netscape.com 1998-11-09 23:30:16 +00:00
Родитель 54ec141a85
Коммит aec75f892e
40 изменённых файлов: 1623 добавлений и 455 удалений

Просмотреть файл

@ -155,7 +155,8 @@ nsHTMLInputElement::nsHTMLInputElement(nsIAtom* aTag)
mType = NS_FORM_INPUT_TEXT; // default value
mForm = nsnull;
mWidget = nsnull;
nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
//nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
}
nsHTMLInputElement::~nsHTMLInputElement()
@ -166,7 +167,7 @@ nsHTMLInputElement::~nsHTMLInputElement()
mForm->RemoveElement(this, PR_FALSE);
NS_RELEASE(mForm);
}
nsTraceRefcnt::Destroy((nsIFormControl*)this, __FILE__, __LINE__);
//nsTraceRefcnt::Destroy((nsIFormControl*)this, __FILE__, __LINE__);
}
// nsISupports
@ -174,7 +175,7 @@ nsHTMLInputElement::~nsHTMLInputElement()
NS_IMETHODIMP_(nsrefcnt)
nsHTMLInputElement::AddRef(void)
{
nsTraceRefcnt::AddRef((nsIFormControl*)this, mRefCnt+1, __FILE__, __LINE__);
//nsTraceRefcnt::AddRef((nsIFormControl*)this, mRefCnt+1, __FILE__, __LINE__);
PRInt32 refCnt = mRefCnt; // debugging
return ++mRefCnt;
}
@ -200,7 +201,7 @@ nsHTMLInputElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMETHODIMP_(nsrefcnt)
nsHTMLInputElement::Release()
{
nsTraceRefcnt::Release((nsIFormControl*)this, mRefCnt-1, __FILE__, __LINE__);
//nsTraceRefcnt::Release((nsIFormControl*)this, mRefCnt-1, __FILE__, __LINE__);
--mRefCnt;
if (mRefCnt <= 0) {
delete this;
@ -242,8 +243,41 @@ nsHTMLInputElement::GetForm(nsIDOMHTMLFormElement** aForm)
return result;
}
NS_IMPL_STRING_ATTR(nsHTMLInputElement, DefaultValue, value)
NS_IMPL_BOOL_ATTR(nsHTMLInputElement, DefaultChecked, defaultchecked)
NS_IMETHODIMP
nsHTMLInputElement::GetDefaultValue(nsString& aDefaultValue)
{
return mInner.GetAttribute(nsHTMLAtoms::value, aDefaultValue);
}
NS_IMETHODIMP
nsHTMLInputElement::SetDefaultValue(const nsString& aDefaultValue)
{
return mInner.SetAttribute(nsHTMLAtoms::value, aDefaultValue, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLInputElement::GetDefaultChecked(PRBool* aDefaultChecked)
{
nsHTMLValue val;
nsresult rv = mInner.GetAttribute(nsHTMLAtoms::checked, val);
*aDefaultChecked = (NS_CONTENT_ATTR_NOT_THERE != rv);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLInputElement::SetDefaultChecked(PRBool aDefaultChecked)
{
nsAutoString empty;
if (aDefaultChecked) {
return mInner.SetAttribute(nsHTMLAtoms::checked, empty, PR_TRUE);
} else {
mInner.UnsetAttribute(nsHTMLAtoms::checked, PR_TRUE);
return NS_OK;
}
}
//NS_IMPL_STRING_ATTR(nsHTMLInputElement, DefaultValue, defaultvalue)
//NS_IMPL_BOOL_ATTR(nsHTMLInputElement, DefaultChecked, defaultchecked)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Accept, accept)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, AccessKey, accesskey)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Align, align)
@ -299,7 +333,6 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
return NS_OK;
}
}
}
@ -330,12 +363,9 @@ nsHTMLInputElement::GetChecked(PRBool* aValue)
return NS_OK;
}
}
}
}
nsHTMLValue val;
nsresult rv = mInner.GetAttribute(nsHTMLAtoms::checked, val);
*aValue = (NS_CONTENT_ATTR_NOT_THERE != rv);
return NS_OK;
return GetDefaultChecked(aValue);
}
@ -344,33 +374,13 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
{
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_CHECKBOX == type) {
if (nsnull != mWidget) {
nsICheckButton* checkbox = nsnull;
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkbox)) {
checkbox->SetState(aValue);
NS_RELEASE(checkbox);
return NS_OK;
}
}
} else if (NS_FORM_INPUT_RADIO == type) {
if (nsnull != mWidget) {
nsIRadioButton* radio = nsnull;
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
radio->SetState(aValue);
NS_RELEASE(radio);
return NS_OK;
}
}
if ((NS_FORM_INPUT_CHECKBOX == type) || (NS_FORM_INPUT_RADIO == type)) {
nsAutoString value;
value = (aValue) ? "1" : "0";
mInner.SetAttribute("checked", value, PR_TRUE);
}
nsAutoString empty;
if (aValue) {
return mInner.SetAttribute(nsHTMLAtoms::checked, empty, PR_TRUE);
} else {
mInner.UnsetAttribute(nsHTMLAtoms::checked, PR_TRUE);
return NS_OK;
}
return SetDefaultChecked(aValue);
}
NS_IMETHODIMP

Просмотреть файл

@ -30,14 +30,14 @@
#include "nsStyleConsts.h"
#include "nsIPresContext.h"
#include "nsIWidget.h"
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsIHTMLAttributes.h"
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement,
public nsIScriptObjectOwner,
@ -237,8 +237,8 @@ NS_IMETHODIMP
nsHTMLTextAreaElement::Select() // XXX not tested
{
if (nsnull != mWidget) {
nsITextWidget *textWidget;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID, (void**)&textWidget)) {
nsITextAreaWidget *textWidget;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textWidget)) {
textWidget->SelectAll();
NS_RELEASE(textWidget);
}
@ -265,15 +265,33 @@ nsHTMLTextAreaElement::GetType(nsString& aType)
NS_IMETHODIMP
nsHTMLTextAreaElement::GetValue(nsString& aValue)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->GetText(aValue,0,size);
NS_RELEASE(text);
return NS_OK;
}
}
return mInner.GetAttribute(nsHTMLAtoms::value, aValue);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::SetValue(const nsString& aValue)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
}
}
return mInner.SetAttribute(nsHTMLAtoms::value, aValue, PR_TRUE);
}
NS_IMETHODIMP
@ -290,7 +308,10 @@ nsHTMLTextAreaElement::SetDefaultValue(const nsString& aDefaultValue)
static char whitespace[] = " \r\n\t";
nsString value(aDefaultValue);
value.Trim(whitespace, PR_TRUE, PR_FALSE);
return mInner.SetAttribute(nsHTMLAtoms::defaultvalue, value, PR_TRUE);
mInner.SetAttribute(nsHTMLAtoms::defaultvalue, value, PR_TRUE);
mInner.SetAttribute(nsHTMLAtoms::value, value, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -41,13 +41,14 @@
#include "nsIViewManager.h"
#include "nsStyleConsts.h"
#include "nsTableOuterFrame.h"
#include "nsIWebShell.h"
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
class HTMLAnchorRule : public nsIStyleRule {
public:
@ -331,9 +332,10 @@ protected:
nsIFrame* aParentFrame,
nsIFrame*& aFrame);
PRBool IsScrollable(const nsStyleDisplay* aDisplay);
PRBool IsScrollable(nsIPresContext* aPresContext, const nsStyleDisplay* aDisplay);
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent);
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
nsIContent* aContent);
PRBool AttributeRequiresRepaint(nsIAtom* aAttribute);
PRBool AttributeRequiresReflow (nsIAtom* aAttribute);
@ -903,7 +905,7 @@ HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent,
rv = NS_NewButtonControlFrame(aContent, aParentFrame, aFrame);
}
else if (val.EqualsIgnoreCase("image")) {
rv = NS_NewButtonControlFrame(aContent, aParentFrame, aFrame);
rv = NS_NewImageControlFrame(aContent, aParentFrame, aFrame);
}
else if (val.EqualsIgnoreCase("password")) {
rv = NS_NewTextControlFrame(aContent, aParentFrame, aFrame);
@ -1383,12 +1385,30 @@ HTMLStyleSheetImpl::GetAdjustedParentFrame(nsIFrame* aCurrentParentFrame,
}
PRBool
HTMLStyleSheetImpl::IsScrollable(const nsStyleDisplay* aDisplay)
HTMLStyleSheetImpl::IsScrollable(nsIPresContext* aPresContext, const nsStyleDisplay* aDisplay)
{
// For the time being it's scrollable if the overflow property is auto or
// scroll, regardless of whether the width or height is fixed in size
if ((NS_STYLE_OVERFLOW_SCROLL == aDisplay->mOverflow) ||
(NS_STYLE_OVERFLOW_AUTO == aDisplay->mOverflow)) {
PRInt32 scrolling = -1;
nsISupports* container;
if (nsnull != aPresContext) {
aPresContext->GetContainer(&container);
if (nsnull != container) {
nsIWebShell* webShell = nsnull;
container->QueryInterface(kIWebShellIID, (void**) &webShell);
if (nsnull != webShell) {
webShell->GetScrolling(scrolling);
NS_RELEASE(webShell);
}
NS_RELEASE(container);
}
}
if (-1 == scrolling) {
scrolling = aDisplay->mOverflow;
}
if ((NS_STYLE_OVERFLOW_SCROLL == scrolling) ||
(NS_STYLE_OVERFLOW_AUTO == scrolling)) {
return PR_TRUE;
}
@ -1457,7 +1477,7 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
// If we're paginated then don't ever make the BODY scrollable
// XXX Use a special BODY rule for paged media
if (!(aPresContext->IsPaginated() && (nsHTMLAtoms::body == tag))) {
if (display->IsBlockLevel() && IsScrollable(display)) {
if (display->IsBlockLevel() && IsScrollable(aPresContext, display)) {
// Create a scroll frame which will wrap the frame that needs to
// be scrolled
if NS_SUCCEEDED(NS_NewScrollFrame(aContent, aParentFrame, scrollFrame)) {
@ -1504,7 +1524,8 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
}
nsIFrame*
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent)
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
nsIContent* aContent)
{
nsIFrame* frame = aPresShell->FindFrameWithContent(aContent);
@ -1514,7 +1535,7 @@ HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent)
const nsStyleDisplay* display;
frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->IsBlockLevel() && IsScrollable(display)) {
if (display->IsBlockLevel() && IsScrollable(aPresContext, display)) {
frame->FirstChild(nsnull, frame);
}
}
@ -1528,7 +1549,7 @@ HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,
PRInt32 aNewIndexInContainer)
{
nsIPresShell* shell = aPresContext->GetShell();
nsIFrame* parentFrame = GetFrameFor(shell, aContainer);
nsIFrame* parentFrame = GetFrameFor(shell, aPresContext, aContainer);
#ifdef NS_DEBUG
if (nsnull == parentFrame) {

Просмотреть файл

@ -163,6 +163,8 @@ public:
NS_IMETHOD SetMarginWidth (PRInt32 aWidth);
NS_IMETHOD GetMarginHeight(PRInt32& aWidth);
NS_IMETHOD SetMarginHeight(PRInt32 aHeight);
NS_IMETHOD GetScrolling(PRInt32& aScrolling);
NS_IMETHOD SetScrolling(PRInt32 aScrolling);
// Document load api's
NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult);
@ -295,6 +297,7 @@ protected:
nsScrollPreference mScrollPref;
PRInt32 mMarginWidth;
PRInt32 mMarginHeight;
PRInt32 mScrolling;
nsVoidArray mRefreshments;
void ReleaseChildren();
@ -400,6 +403,7 @@ nsWebShell::nsWebShell()
mScriptContext = nsnull;
mMarginWidth = -1;
mMarginHeight = -1;
mScrolling = -1;
}
nsWebShell::~nsWebShell()
@ -609,7 +613,7 @@ nsWebShell::Init(nsNativeWidget aNativeParent,
CreatePluginHost(aAllowPlugins);
mScrollPref = aScrolling;
//mScrollPref = aScrolling;
WEB_TRACE(WEB_TRACE_CALLS,
("nsWebShell::Init: this=%p", this));
@ -1042,6 +1046,19 @@ nsWebShell::SetMarginHeight(PRInt32 aHeight)
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::GetScrolling(PRInt32& aScrolling)
{
aScrolling = mScrolling;
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetScrolling(PRInt32 aScrolling)
{
mScrolling = aScrolling;
return NS_OK;
}
/**
* Document Load methods
*/

Просмотреть файл

@ -312,6 +312,15 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext,
return NS_OK;
}
NS_IMETHODIMP
nsFormControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
return NS_OK;
}
nsWidgetInitData*
nsFormControlFrame::GetWidgetInitData(nsIPresContext& aPresContext)
{

Просмотреть файл

@ -125,6 +125,10 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
// new behavior
/**

Просмотреть файл

@ -0,0 +1,395 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsHTMLImage.h"
#include "nsIFormControlFrame.h"
#include "nsIFormControl.h"
#include "nsHTMLParts.h"
#include "nsIRenderingContext.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIStyleContext.h"
#include "nsLeafFrame.h"
#include "nsCSSRendering.h"
#include "nsHTMLIIDs.h"
#include "nsIViewManager.h"
#include "nsISupports.h"
#include "nsHTMLAtoms.h"
#include "nsIView.h"
#include "nsViewsCID.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsIImage.h"
#include "nsStyleUtil.h"
#include "nsDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIHTMLAttributes.h"
#include "nsGenericHTMLElement.h"
#include "nsFormFrame.h"
//Enumeration of possible mouse states used to detect mouse clicks
enum nsMouseState {
eMouseNone,
eMouseEnter,
eMouseDown,
eMouseExit
};
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
class nsImageControlFrame : public ImageFrame,
public nsIFormControlFrame
{
public:
nsImageControlFrame(nsIContent* aContent, nsIFrame* aParentFrame);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD Init(nsIPresContext& aPresContext, nsIFrame* aChildList);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
virtual void MouseClicked(nsIPresContext* aPresContext);
virtual void SetFormFrame(nsFormFrame* aFormFrame) { mFormFrame = aFormFrame; }
PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
virtual PRInt32 GetMaxNumValues();
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
NS_IMETHOD GetType(PRInt32* aType) const;
NS_IMETHOD GetName(nsString* aName);
virtual void Reset() {};
void SetFocus(PRBool aOn, PRBool aRepaint);
protected:
virtual ~nsImageControlFrame();
void GetTranslatedRect(nsRect& aRect); // XXX this implementation is a copy of nsHTMLButtonControlFrame
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
nsFormFrame* mFormFrame;
nsMouseState mLastMouseState;
nsPoint mLastClickPoint;
nsCursor mPreviousCursor;
nsRect mTranslatedRect;
PRBool mGotFocus;
};
nsImageControlFrame::nsImageControlFrame(nsIContent* aContent,
nsIFrame* aParentFrame)
: ImageFrame(aContent, aParentFrame)
{
mLastMouseState = eMouseNone;
mLastClickPoint = nsPoint(0,0);
mPreviousCursor = eCursor_standard;
mTranslatedRect = nsRect(0,0,0,0);
mGotFocus = PR_FALSE;
}
nsImageControlFrame::~nsImageControlFrame()
{
}
nsresult
NS_NewImageControlFrame(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame*& aResult)
{
aResult = new nsImageControlFrame(aContent, aParent);
if (nsnull == aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
nsresult
nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIFormControlFrameIID)) {
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
return NS_OK;
}
return ImageFrame::QueryInterface(aIID, aInstancePtr);
}
nsrefcnt nsImageControlFrame::AddRef(void)
{
NS_WARNING("not supported");
return 1;
}
nsrefcnt nsImageControlFrame::Release(void)
{
NS_WARNING("not supported");
return 1;
}
NS_IMETHODIMP
nsImageControlFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList)
{
nsFormFrame::AddFormControlFrame(aPresContext, *this);
if (nsnull == mFormFrame) {
return NS_OK;
}
// add ourself as an nsIFormControlFrame
nsFormFrame::AddFormControlFrame(aPresContext, *this);
// create our view, we need a view to grab the mouse
nsIView* view;
GetView(view);
if (!view) {
nsresult result = nsRepository::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&view);
nsIPresShell *presShell = aPresContext.GetShell();
nsIViewManager *viewMan = presShell->GetViewManager();
NS_RELEASE(presShell);
nsIFrame* parWithView;
nsIView *parView;
GetParentWithView(parWithView);
parWithView->GetView(parView);
// the view's size is not know yet, but its size will be kept in synch with our frame.
nsRect boundBox(0, 0, 500, 500);
result = view->Init(viewMan, boundBox, parView, nsnull);
viewMan->InsertChild(parView, view, 0);
SetView(view);
const nsStyleColor* color = (const nsStyleColor*) mStyleContext->GetStyleData(eStyleStruct_Color);
// set the opacity
viewMan->SetViewOpacity(view, color->mOpacity);
NS_RELEASE(viewMan);
}
return NS_OK;
}
NS_METHOD
nsImageControlFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if (nsFormFrame::GetDisabled(this)) { // XXX cache disabled
return NS_OK;
}
aEventStatus = nsEventStatus_eIgnore;
nsresult result = NS_OK;
nsIView* view;
GetView(view);
if (view) {
nsIViewManager* viewMan;
view->GetViewManager(viewMan);
if (viewMan) {
nsIView* grabber;
viewMan->GetMouseEventGrabber(grabber);
if ((grabber == view) || (nsnull == grabber)) {
nsIWidget* window;
PRBool ignore;
switch (aEvent->message) {
case NS_MOUSE_ENTER: // not implemented yet on frames, 1st mouse move simulates it
mLastMouseState = eMouseEnter;
break;
case NS_MOUSE_LEFT_BUTTON_DOWN:
mLastMouseState = eMouseDown;
mGotFocus = PR_TRUE;
break;
case NS_MOUSE_MOVE:
//printf ("%d mRect=(%d,%d,%d,%d), x=%d, y=%d \n", foo++, mRect.x, mRect.y, mRect.width, mRect.height, aEvent->point.x, aEvent->point.y);
if (nsnull == grabber) { // simulated mouse enter
GetTranslatedRect(mTranslatedRect);
//printf("%d enter\n", foo++);
viewMan->GrabMouseEvents(view, ignore);
GetWindow(window);
if (window) {
mPreviousCursor = window->GetCursor();
window->SetCursor(eCursor_select); // set it to something else to work around bug
window->SetCursor(eCursor_standard);
NS_RELEASE(window);
}
mLastMouseState = eMouseEnter;
// simulated mouse exit
} else if (!mTranslatedRect.Contains(aEvent->point)) {
viewMan->GrabMouseEvents(nsnull, ignore);
GetWindow(window);
if (window) {
window->SetCursor(mPreviousCursor);
NS_RELEASE(window);
}
mLastMouseState = eMouseExit;
}
break;
case NS_MOUSE_LEFT_BUTTON_UP:
{
if (eMouseDown == mLastMouseState) {
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_MOUSE_EVENT;
event.message = NS_MOUSE_LEFT_CLICK;
mContent->HandleDOMEvent(aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
float t2p = aPresContext.GetTwipsToPixels();
mLastClickPoint.x = NSTwipsToIntPixels(aEvent->point.x - mTranslatedRect.x, t2p);
mLastClickPoint.y = NSTwipsToIntPixels(aEvent->point.y - mTranslatedRect.y, t2p);
if (nsEventStatus_eConsumeNoDefault != status) {
MouseClicked(&aPresContext);
}
mLastMouseState = eMouseEnter;
}
break;
}
case NS_MOUSE_EXIT: // doesn't work for frames, yet
break;
}
aEventStatus = nsEventStatus_eConsumeNoDefault;
NS_RELEASE(viewMan);
return NS_OK;
}
}
}
return ImageFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
void
nsImageControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
{
mGotFocus = aOn;
if (aRepaint) {
nsRect rect(0, 0, mRect.width, mRect.height);
Invalidate(rect, PR_TRUE);
}
}
void
nsImageControlFrame::GetTranslatedRect(nsRect& aRect)
{
nsIView* view;
nsPoint viewOffset(0,0);
GetOffsetFromView(viewOffset, view);
while (nsnull != view) {
nsPoint tempOffset;
view->GetPosition(&tempOffset.x, &tempOffset.y);
viewOffset += tempOffset;
view->GetParent(view);
}
aRect = nsRect(viewOffset.x, viewOffset.y, mRect.width, mRect.height);
}
NS_IMETHODIMP
nsImageControlFrame::GetType(PRInt32* aType) const
{
*aType = NS_FORM_INPUT_IMAGE;
return NS_OK;
}
NS_IMETHODIMP
nsImageControlFrame::GetName(nsString* aResult)
{
if (nsnull == aResult) {
return NS_OK;
} else {
return nsFormFrame::GetName(this, *aResult);
}
}
PRBool
nsImageControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
if (this == (aSubmitter)) {
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
return PR_FALSE;
}
PRInt32
nsImageControlFrame::GetMaxNumValues()
{
return 2;
}
PRBool
nsImageControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)
{
nsAutoString name;
nsresult result = GetName(&name);
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_HAS_VALUE != result)) {
return PR_FALSE;
}
nsAutoString value;
nsresult valResult = nsFormFrame::GetValue(this, value);
char buf[20];
aNumValues = 2;
aValues[0].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.x);
aValues[0].Append(&buf[0]);
aNames[0] = name;
aNames[0].Append(".x");
aValues[1].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.y);
aValues[1].Append(&buf[0]);
aNames[1] = name;
aNames[1].Append(".y");
return PR_TRUE;
}
void
nsImageControlFrame::MouseClicked(nsIPresContext* aPresContext)
{
PRInt32 type;
GetType(&type);
if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) {
nsEventStatus status;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SUBMIT;
mContent->HandleDOMEvent(*aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
if (nsEventStatus_eConsumeNoDefault != status) {
mFormFrame->OnSubmit(aPresContext, this);
}
}
}

Просмотреть файл

@ -264,7 +264,7 @@ nsTextControlFrame::GetText(nsString* aText)
nsIDOMHTMLInputElement* textElem = nsnull;
result = mContent->QueryInterface(kIDOMHTMLInputElementIID, (void**)&textElem);
if ((NS_OK == result) && textElem) {
result = textElem->GetValue(*aText);
result = textElem->GetDefaultValue(*aText);
NS_RELEASE(textElem);
}
} else {
@ -278,6 +278,41 @@ nsTextControlFrame::GetText(nsString* aText)
return result;
}
NS_IMETHODIMP
nsTextControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
PRInt32 type;
GetType(&type);
if (mWidget) {
nsITextWidget* text = nsnull;
result = mWidget->QueryInterface(kITextWidgetIID, (void**)&text);
if ((NS_SUCCEEDED(result)) && (nsnull != text)) {
if (nsHTMLAtoms::value == aAttribute) {
nsString value;
nsresult result = GetText(&value);
PRUint32 ignore;
text->SetText(value, ignore);
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
} else if (nsHTMLAtoms::size == aAttribute) {
nsFormFrame::StyleChangeReflow(aPresContext, this);
} else if (nsHTMLAtoms::maxlength == aAttribute) {
PRInt32 maxLength;
nsresult result = GetMaxLength(&maxLength);
if (NS_CONTENT_ATTR_NOT_THERE != result) {
text->SetMaxTextLength(maxLength);
}
}
NS_RELEASE(text);
}
return result;
}
void
nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
@ -298,19 +333,7 @@ nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext,
PRUint32 ignore;
nsAutoString value;
// XXX Workaround for "text" input elements not initializing their widget
// to the initial value. See http://www.cnet.com
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
// Use the default value, because the widget has just been created and
// we're setting its initial value
nsIDOMHTMLInputElement* textElem = nsnull;
if (NS_SUCCEEDED(mContent->QueryInterface(kIDOMHTMLInputElementIID, (void**)&textElem))) {
textElem->GetDefaultValue(value);
NS_RELEASE(textElem);
}
} else {
GetText(&value);
}
GetText(&value);
nsITextAreaWidget* textArea = nsnull;
nsITextWidget* text = nsnull;

Просмотреть файл

@ -30,6 +30,11 @@ public:
virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext& aPresContext);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);

Просмотреть файл

@ -164,7 +164,7 @@ public:
NS_IMETHOD GetParentContent(nsIContent*& aContent);
PRBool GetURL(nsIContent* aContent, nsString& aResult);
PRBool GetName(nsIContent* aContent, nsString& aResult);
nsScrollPreference GetScrolling(nsIContent* aContent, PRBool aStandardMode);
PRInt32 GetScrolling(nsIContent* aContent, PRBool aStandardMode);
nsFrameborder GetFrameBorder(PRBool aStandardMode);
PRInt32 GetMarginWidth(nsIPresContext* aPresContext, nsIContent* aContent);
PRInt32 GetMarginHeight(nsIPresContext* aPresContext, nsIContent* aContent);
@ -457,7 +457,7 @@ PRBool nsHTMLFrameInnerFrame::GetName(nsIContent* aContent, nsString& aResult)
return result;
}
nsScrollPreference nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent, PRBool aStandardMode)
PRInt32 nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent, PRBool aStandardMode)
{
nsIHTMLContent* content = nsnull;
aContent->QueryInterface(kIHTMLContentIID, (void**) &content);
@ -465,30 +465,30 @@ nsScrollPreference nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent, PRB
nsHTMLValue value;
if (NS_CONTENT_ATTR_HAS_VALUE == (content->GetAttribute(nsHTMLAtoms::scrolling, value))) {
if (eHTMLUnit_Enumerated == value.GetUnit()) {
PRInt32 returnValue;
PRInt32 intValue;
intValue = value.GetIntValue();
if (!aStandardMode) {
if ((NS_STYLE_FRAME_ON == intValue) || (NS_STYLE_FRAME_SCROLL == intValue)) {
intValue = NS_STYLE_FRAME_YES;
}
else if ((NS_STYLE_FRAME_OFF == intValue) || (NS_STYLE_FRAME_NOSCROLL == intValue)) {
} else if ((NS_STYLE_FRAME_OFF == intValue) || (NS_STYLE_FRAME_NOSCROLL == intValue)) {
intValue = NS_STYLE_FRAME_NO;
}
}
if (NS_STYLE_FRAME_YES == intValue) {
NS_RELEASE(content);
return nsScrollPreference_kAlwaysScroll;
}
else if (NS_STYLE_FRAME_NO == intValue) {
NS_RELEASE(content);
return nsScrollPreference_kNeverScroll;
returnValue = NS_STYLE_OVERFLOW_SCROLL;
} else if (NS_STYLE_FRAME_NO == intValue) {
returnValue = NS_STYLE_OVERFLOW_HIDDEN;
} else if (NS_STYLE_FRAME_AUTO == intValue) {
returnValue = NS_STYLE_OVERFLOW_AUTO;
}
NS_RELEASE(content);
return returnValue;
}
}
NS_RELEASE(content);
}
// XXX if we get here, check for nsIDOMFRAMEElement, nsIDOMIFRAMEElement interfaces
return nsScrollPreference_kAuto;
return -1;
}
nsFrameborder nsHTMLFrameInnerFrame::GetFrameBorder(PRBool aStandardMode)
@ -633,9 +633,12 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext,
return rv;
}
// pass along marginwidth, marginheight so sub document can use it
// pass along marginwidth, marginheight, scrolling so sub document can use it
mWebShell->SetMarginWidth(GetMarginWidth(&aPresContext, content));
mWebShell->SetMarginHeight(GetMarginHeight(&aPresContext, content));
nsCompatibility mode;
aPresContext.GetCompatibilityMode(mode);
mWebShell->SetScrolling(GetScrolling(content, mode));
nsString frameName;
if (GetName(content, frameName)) {
@ -704,8 +707,8 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext,
mWebShell->Init(widget->GetNativeData(NS_NATIVE_WIDGET),
webBounds.x, webBounds.y,
webBounds.width, webBounds.height,
GetScrolling(content, PR_FALSE));
webBounds.width, webBounds.height);
//GetScrolling(content, PR_FALSE));
NS_RELEASE(content);
NS_RELEASE(widget);

Просмотреть файл

@ -320,6 +320,10 @@ extern nsresult
NS_NewButtonControlFrame(nsIContent* aContent, nsIFrame* aParentFrame,
nsIFrame*& aResult);
extern nsresult
NS_NewImageControlFrame(nsIContent* aContent, nsIFrame* aParentFrame,
nsIFrame*& aResult);
extern nsresult
NS_NewHTMLButtonControlFrame(nsIContent* aContent, nsIFrame* aParentFrame,
nsIFrame*& aResult);

Просмотреть файл

@ -52,66 +52,6 @@
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
#define ImageFrameSuper nsLeafFrame
class ImageFrame : public ImageFrameSuper {
public:
ImageFrame(nsIContent* aContent, nsIFrame* aParentFrame);
NS_IMETHOD DeleteFrame(nsIPresContext& aPresContext);
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_METHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame,
nsIContent** aContent,
PRInt32& aCursor);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
protected:
virtual ~ImageFrame();
void SizeOfWithoutThis(nsISizeOfHandler* aHandler) const;
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
nsIImageMap* GetImageMap();
nsHTMLImageLoader mImageLoader;
nsIImageMap* mImageMap;
PRBool mSizeFrozen;
void TriggerLink(nsIPresContext& aPresContext,
const nsString& aURLSpec,
const nsString& aTargetSpec,
PRBool aClick);
PRBool IsServerImageMap();
PRIntn GetSuppress();
nscoord MeasureString(const PRUnichar* aString,
PRInt32 aLength,
nscoord aMaxWidth,
PRUint32& aMaxFit,
nsIRenderingContext& aContext);
void DisplayAltText(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsString& aAltText,
const nsRect& aRect);
void DisplayAltFeedback(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
PRInt32 aIconId);
};
// Value's for mSuppress
#define SUPPRESS_UNSET 0

Просмотреть файл

@ -18,6 +18,7 @@
#ifndef nsHTMLImage_h___
#define nsHTMLImage_h___
#include "nsLeafFrame.h"
#include "nslayout.h"
#include "nsIFrameImageLoader.h"
#include "nsString.h"
@ -25,6 +26,7 @@ class nsIFrame;
class nsIFrameImageLoader;
class nsIPresContext;
class nsISizeOfHandler;
class nsIImageMap;
struct nsHTMLReflowState;
struct nsHTMLReflowMetrics;
struct nsSize;
@ -91,4 +93,66 @@ protected:
nsString* mBaseHREF;
};
#define ImageFrameSuper nsLeafFrame
class ImageFrame : public ImageFrameSuper {
public:
ImageFrame(nsIContent* aContent, nsIFrame* aParentFrame);
NS_IMETHOD DeleteFrame(nsIPresContext& aPresContext);
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_METHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame,
nsIContent** aContent,
PRInt32& aCursor);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
protected:
virtual ~ImageFrame();
void SizeOfWithoutThis(nsISizeOfHandler* aHandler) const;
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
nsIImageMap* GetImageMap();
nsHTMLImageLoader mImageLoader;
nsIImageMap* mImageMap;
PRBool mSizeFrozen;
void TriggerLink(nsIPresContext& aPresContext,
const nsString& aURLSpec,
const nsString& aTargetSpec,
PRBool aClick);
PRBool IsServerImageMap();
PRIntn GetSuppress();
nscoord MeasureString(const PRUnichar* aString,
PRInt32 aLength,
nscoord aMaxWidth,
PRUint32& aMaxFit,
nsIRenderingContext& aContext);
void DisplayAltText(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsString& aAltText,
const nsRect& aRect);
void DisplayAltFeedback(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
PRInt32 aIconId);
};
#endif /* nsHTMLImage_h___ */

Просмотреть файл

@ -320,6 +320,10 @@ extern nsresult
NS_NewButtonControlFrame(nsIContent* aContent, nsIFrame* aParentFrame,
nsIFrame*& aResult);
extern nsresult
NS_NewImageControlFrame(nsIContent* aContent, nsIFrame* aParentFrame,
nsIFrame*& aResult);
extern nsresult
NS_NewHTMLButtonControlFrame(nsIContent* aContent, nsIFrame* aParentFrame,
nsIFrame*& aResult);

Просмотреть файл

@ -52,66 +52,6 @@
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
#define ImageFrameSuper nsLeafFrame
class ImageFrame : public ImageFrameSuper {
public:
ImageFrame(nsIContent* aContent, nsIFrame* aParentFrame);
NS_IMETHOD DeleteFrame(nsIPresContext& aPresContext);
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_METHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame,
nsIContent** aContent,
PRInt32& aCursor);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
protected:
virtual ~ImageFrame();
void SizeOfWithoutThis(nsISizeOfHandler* aHandler) const;
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
nsIImageMap* GetImageMap();
nsHTMLImageLoader mImageLoader;
nsIImageMap* mImageMap;
PRBool mSizeFrozen;
void TriggerLink(nsIPresContext& aPresContext,
const nsString& aURLSpec,
const nsString& aTargetSpec,
PRBool aClick);
PRBool IsServerImageMap();
PRIntn GetSuppress();
nscoord MeasureString(const PRUnichar* aString,
PRInt32 aLength,
nscoord aMaxWidth,
PRUint32& aMaxFit,
nsIRenderingContext& aContext);
void DisplayAltText(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsString& aAltText,
const nsRect& aRect);
void DisplayAltFeedback(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
PRInt32 aIconId);
};
// Value's for mSuppress
#define SUPPRESS_UNSET 0

Просмотреть файл

@ -155,7 +155,8 @@ nsHTMLInputElement::nsHTMLInputElement(nsIAtom* aTag)
mType = NS_FORM_INPUT_TEXT; // default value
mForm = nsnull;
mWidget = nsnull;
nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
//nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
}
nsHTMLInputElement::~nsHTMLInputElement()
@ -166,7 +167,7 @@ nsHTMLInputElement::~nsHTMLInputElement()
mForm->RemoveElement(this, PR_FALSE);
NS_RELEASE(mForm);
}
nsTraceRefcnt::Destroy((nsIFormControl*)this, __FILE__, __LINE__);
//nsTraceRefcnt::Destroy((nsIFormControl*)this, __FILE__, __LINE__);
}
// nsISupports
@ -174,7 +175,7 @@ nsHTMLInputElement::~nsHTMLInputElement()
NS_IMETHODIMP_(nsrefcnt)
nsHTMLInputElement::AddRef(void)
{
nsTraceRefcnt::AddRef((nsIFormControl*)this, mRefCnt+1, __FILE__, __LINE__);
//nsTraceRefcnt::AddRef((nsIFormControl*)this, mRefCnt+1, __FILE__, __LINE__);
PRInt32 refCnt = mRefCnt; // debugging
return ++mRefCnt;
}
@ -200,7 +201,7 @@ nsHTMLInputElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMETHODIMP_(nsrefcnt)
nsHTMLInputElement::Release()
{
nsTraceRefcnt::Release((nsIFormControl*)this, mRefCnt-1, __FILE__, __LINE__);
//nsTraceRefcnt::Release((nsIFormControl*)this, mRefCnt-1, __FILE__, __LINE__);
--mRefCnt;
if (mRefCnt <= 0) {
delete this;
@ -242,8 +243,41 @@ nsHTMLInputElement::GetForm(nsIDOMHTMLFormElement** aForm)
return result;
}
NS_IMPL_STRING_ATTR(nsHTMLInputElement, DefaultValue, value)
NS_IMPL_BOOL_ATTR(nsHTMLInputElement, DefaultChecked, defaultchecked)
NS_IMETHODIMP
nsHTMLInputElement::GetDefaultValue(nsString& aDefaultValue)
{
return mInner.GetAttribute(nsHTMLAtoms::value, aDefaultValue);
}
NS_IMETHODIMP
nsHTMLInputElement::SetDefaultValue(const nsString& aDefaultValue)
{
return mInner.SetAttribute(nsHTMLAtoms::value, aDefaultValue, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLInputElement::GetDefaultChecked(PRBool* aDefaultChecked)
{
nsHTMLValue val;
nsresult rv = mInner.GetAttribute(nsHTMLAtoms::checked, val);
*aDefaultChecked = (NS_CONTENT_ATTR_NOT_THERE != rv);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLInputElement::SetDefaultChecked(PRBool aDefaultChecked)
{
nsAutoString empty;
if (aDefaultChecked) {
return mInner.SetAttribute(nsHTMLAtoms::checked, empty, PR_TRUE);
} else {
mInner.UnsetAttribute(nsHTMLAtoms::checked, PR_TRUE);
return NS_OK;
}
}
//NS_IMPL_STRING_ATTR(nsHTMLInputElement, DefaultValue, defaultvalue)
//NS_IMPL_BOOL_ATTR(nsHTMLInputElement, DefaultChecked, defaultchecked)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Accept, accept)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, AccessKey, accesskey)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Align, align)
@ -299,7 +333,6 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
return NS_OK;
}
}
}
@ -330,12 +363,9 @@ nsHTMLInputElement::GetChecked(PRBool* aValue)
return NS_OK;
}
}
}
}
nsHTMLValue val;
nsresult rv = mInner.GetAttribute(nsHTMLAtoms::checked, val);
*aValue = (NS_CONTENT_ATTR_NOT_THERE != rv);
return NS_OK;
return GetDefaultChecked(aValue);
}
@ -344,33 +374,13 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
{
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_CHECKBOX == type) {
if (nsnull != mWidget) {
nsICheckButton* checkbox = nsnull;
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkbox)) {
checkbox->SetState(aValue);
NS_RELEASE(checkbox);
return NS_OK;
}
}
} else if (NS_FORM_INPUT_RADIO == type) {
if (nsnull != mWidget) {
nsIRadioButton* radio = nsnull;
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
radio->SetState(aValue);
NS_RELEASE(radio);
return NS_OK;
}
}
if ((NS_FORM_INPUT_CHECKBOX == type) || (NS_FORM_INPUT_RADIO == type)) {
nsAutoString value;
value = (aValue) ? "1" : "0";
mInner.SetAttribute("checked", value, PR_TRUE);
}
nsAutoString empty;
if (aValue) {
return mInner.SetAttribute(nsHTMLAtoms::checked, empty, PR_TRUE);
} else {
mInner.UnsetAttribute(nsHTMLAtoms::checked, PR_TRUE);
return NS_OK;
}
return SetDefaultChecked(aValue);
}
NS_IMETHODIMP

Просмотреть файл

@ -30,14 +30,14 @@
#include "nsStyleConsts.h"
#include "nsIPresContext.h"
#include "nsIWidget.h"
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsIHTMLAttributes.h"
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement,
public nsIScriptObjectOwner,
@ -237,8 +237,8 @@ NS_IMETHODIMP
nsHTMLTextAreaElement::Select() // XXX not tested
{
if (nsnull != mWidget) {
nsITextWidget *textWidget;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID, (void**)&textWidget)) {
nsITextAreaWidget *textWidget;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textWidget)) {
textWidget->SelectAll();
NS_RELEASE(textWidget);
}
@ -265,15 +265,33 @@ nsHTMLTextAreaElement::GetType(nsString& aType)
NS_IMETHODIMP
nsHTMLTextAreaElement::GetValue(nsString& aValue)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->GetText(aValue,0,size);
NS_RELEASE(text);
return NS_OK;
}
}
return mInner.GetAttribute(nsHTMLAtoms::value, aValue);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::SetValue(const nsString& aValue)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
}
}
return mInner.SetAttribute(nsHTMLAtoms::value, aValue, PR_TRUE);
}
NS_IMETHODIMP
@ -290,7 +308,10 @@ nsHTMLTextAreaElement::SetDefaultValue(const nsString& aDefaultValue)
static char whitespace[] = " \r\n\t";
nsString value(aDefaultValue);
value.Trim(whitespace, PR_TRUE, PR_FALSE);
return mInner.SetAttribute(nsHTMLAtoms::defaultvalue, value, PR_TRUE);
mInner.SetAttribute(nsHTMLAtoms::defaultvalue, value, PR_TRUE);
mInner.SetAttribute(nsHTMLAtoms::value, value, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -164,7 +164,7 @@ public:
NS_IMETHOD GetParentContent(nsIContent*& aContent);
PRBool GetURL(nsIContent* aContent, nsString& aResult);
PRBool GetName(nsIContent* aContent, nsString& aResult);
nsScrollPreference GetScrolling(nsIContent* aContent, PRBool aStandardMode);
PRInt32 GetScrolling(nsIContent* aContent, PRBool aStandardMode);
nsFrameborder GetFrameBorder(PRBool aStandardMode);
PRInt32 GetMarginWidth(nsIPresContext* aPresContext, nsIContent* aContent);
PRInt32 GetMarginHeight(nsIPresContext* aPresContext, nsIContent* aContent);
@ -457,7 +457,7 @@ PRBool nsHTMLFrameInnerFrame::GetName(nsIContent* aContent, nsString& aResult)
return result;
}
nsScrollPreference nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent, PRBool aStandardMode)
PRInt32 nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent, PRBool aStandardMode)
{
nsIHTMLContent* content = nsnull;
aContent->QueryInterface(kIHTMLContentIID, (void**) &content);
@ -465,30 +465,30 @@ nsScrollPreference nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent, PRB
nsHTMLValue value;
if (NS_CONTENT_ATTR_HAS_VALUE == (content->GetAttribute(nsHTMLAtoms::scrolling, value))) {
if (eHTMLUnit_Enumerated == value.GetUnit()) {
PRInt32 returnValue;
PRInt32 intValue;
intValue = value.GetIntValue();
if (!aStandardMode) {
if ((NS_STYLE_FRAME_ON == intValue) || (NS_STYLE_FRAME_SCROLL == intValue)) {
intValue = NS_STYLE_FRAME_YES;
}
else if ((NS_STYLE_FRAME_OFF == intValue) || (NS_STYLE_FRAME_NOSCROLL == intValue)) {
} else if ((NS_STYLE_FRAME_OFF == intValue) || (NS_STYLE_FRAME_NOSCROLL == intValue)) {
intValue = NS_STYLE_FRAME_NO;
}
}
if (NS_STYLE_FRAME_YES == intValue) {
NS_RELEASE(content);
return nsScrollPreference_kAlwaysScroll;
}
else if (NS_STYLE_FRAME_NO == intValue) {
NS_RELEASE(content);
return nsScrollPreference_kNeverScroll;
returnValue = NS_STYLE_OVERFLOW_SCROLL;
} else if (NS_STYLE_FRAME_NO == intValue) {
returnValue = NS_STYLE_OVERFLOW_HIDDEN;
} else if (NS_STYLE_FRAME_AUTO == intValue) {
returnValue = NS_STYLE_OVERFLOW_AUTO;
}
NS_RELEASE(content);
return returnValue;
}
}
NS_RELEASE(content);
}
// XXX if we get here, check for nsIDOMFRAMEElement, nsIDOMIFRAMEElement interfaces
return nsScrollPreference_kAuto;
return -1;
}
nsFrameborder nsHTMLFrameInnerFrame::GetFrameBorder(PRBool aStandardMode)
@ -633,9 +633,12 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext,
return rv;
}
// pass along marginwidth, marginheight so sub document can use it
// pass along marginwidth, marginheight, scrolling so sub document can use it
mWebShell->SetMarginWidth(GetMarginWidth(&aPresContext, content));
mWebShell->SetMarginHeight(GetMarginHeight(&aPresContext, content));
nsCompatibility mode;
aPresContext.GetCompatibilityMode(mode);
mWebShell->SetScrolling(GetScrolling(content, mode));
nsString frameName;
if (GetName(content, frameName)) {
@ -704,8 +707,8 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext,
mWebShell->Init(widget->GetNativeData(NS_NATIVE_WIDGET),
webBounds.x, webBounds.y,
webBounds.width, webBounds.height,
GetScrolling(content, PR_FALSE));
webBounds.width, webBounds.height);
//GetScrolling(content, PR_FALSE));
NS_RELEASE(content);
NS_RELEASE(widget);

Просмотреть файл

@ -37,6 +37,7 @@ CPPSRCS = \
nsLegendFrame.cpp \
nsHTMLButtonControlFrame.cpp \
nsLabelFrame.cpp \
nsImageControlFrame.cpp \
$(NULL)
MODULE = raptor

Просмотреть файл

@ -25,14 +25,16 @@ REQUIRES=xpcom raptor js
CPPSRCS=nsFormFrame.cpp nsFormControlFrame.cpp nsButtonControlFrame.cpp nsCheckboxControlFrame.cpp \
nsFileControlFrame.cpp nsRadioControlFrame.cpp nsTextControlFrame.cpp nsSelectControlFrame.cpp \
nsFieldSetFrame.cpp nsLegendFrame.cpp nsHTMLButtonControlFrame.cpp nsLabelFrame.cpp
nsFieldSetFrame.cpp nsLegendFrame.cpp nsHTMLButtonControlFrame.cpp nsLabelFrame.cpp \
nsImageControlFrame.cpp
CPP_OBJS=.\$(OBJDIR)\nsFormFrame.obj .\$(OBJDIR)\nsFormControlFrame.obj \
.\$(OBJDIR)\nsButtonControlFrame.obj .\$(OBJDIR)\nsCheckboxControlFrame.obj \
.\$(OBJDIR)\nsFileControlFrame.obj .\$(OBJDIR)\nsRadioControlFrame.obj \
.\$(OBJDIR)\nsTextControlFrame.obj .\$(OBJDIR)\nsSelectControlFrame.obj \
.\$(OBJDIR)\nsFieldSetFrame.obj .\$(OBJDIR)\nsLegendFrame.obj \
.\$(OBJDIR)\nsHTMLButtonControlFrame.obj .\$(OBJDIR)\nsLabelFrame.obj
.\$(OBJDIR)\nsHTMLButtonControlFrame.obj .\$(OBJDIR)\nsLabelFrame.obj \
.\$(OBJDIR)\nsImageControlFrame.obj
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
-I$(PUBLIC)\dom -I$(PUBLIC)\netlib \

Просмотреть файл

@ -37,15 +37,12 @@
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsIFormControl.h"
#include "nsIImage.h"
#include "nsHTMLImage.h"
#include "nsStyleUtil.h"
#include "nsDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIHTMLAttributes.h"
#include "nsGenericHTMLElement.h"
#include "nsFormFrame.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
@ -86,8 +83,6 @@ nsButtonControlFrame::GetMaxNumValues()
GetType(&type);
if ((NS_FORM_INPUT_SUBMIT == type) || (NS_FORM_INPUT_HIDDEN == type)) {
return 1;
} else if (NS_FORM_INPUT_IMAGE == type) {
return 2;
} else {
return 0;
}
@ -106,38 +101,17 @@ nsButtonControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
PRInt32 type;
GetType(&type);
nsAutoString value;
nsresult valResult = GetValue(&value);
if ((NS_FORM_INPUT_IMAGE == type) || (NS_FORM_INPUT_BUTTON == type)) {
char buf[20];
aNumValues = 2;
aValues[0].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.x);
aValues[0].Append(&buf[0]);
aNames[0] = name;
aNames[0].Append(".x");
aValues[1].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.y);
aValues[1].Append(&buf[0]);
aNames[1] = name;
aNames[1].Append(".y");
return PR_TRUE;
}
else if (((NS_FORM_INPUT_SUBMIT == type) || (NS_FORM_INPUT_HIDDEN == type)) &&
(NS_CONTENT_ATTR_HAS_VALUE == valResult)) {
if (NS_FORM_INPUT_RESET == type) {
aNumValues = 0;
return PR_FALSE;
} else {
nsAutoString value;
nsresult valResult = GetValue(&value);
aValues[0] = value;
aNames[0] = name;
aNumValues = 1;
return PR_TRUE;
} else {
aNumValues = 0;
return PR_FALSE;
}
}
@ -214,6 +188,34 @@ nsButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
#endif
}
NS_IMETHODIMP
nsButtonControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
PRInt32 type;
GetType(&type);
if (mWidget) {
if (nsHTMLAtoms::value == aAttribute) {
nsIButton* button = nsnull;
result = mWidget->QueryInterface(kIButtonIID, (void**)&button);
if ((NS_SUCCEEDED(result)) && (nsnull != button)) {
nsString value;
nsresult result = GetValue(&value);
button->SetLabel(value);
NS_RELEASE(button);
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
} else if (nsHTMLAtoms::size == aAttribute) {
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
}
return result;
}
NS_METHOD
nsButtonControlFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
@ -226,24 +228,7 @@ nsButtonControlFrame::Paint(nsIPresContext& aPresContext,
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
if (disp->mVisible) {
// let super do processing if there is no image
if (NS_FORM_INPUT_IMAGE != type) {
return nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
}
// First paint background and borders
nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
nsIImage* image = mImageLoader.GetImage();
if (nsnull == image) {
// No image yet
return NS_OK;
}
// Now render the image into our inner area (the area without the
nsRect inner;
GetInnerArea(&aPresContext, inner);
aRenderingContext.DrawImage(image, inner);
return nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
}
return NS_OK;
@ -254,27 +239,30 @@ nsButtonControlFrame::MouseClicked(nsIPresContext* aPresContext)
{
PRInt32 type;
GetType(&type);
if (nsnull != mFormFrame) {
if (NS_FORM_INPUT_RESET == type) {
//Send DOM event
nsEventStatus mStatus;
nsEvent mEvent;
mEvent.eventStructType = NS_EVENT;
mEvent.message = NS_FORM_RESET;
mContent->HandleDOMEvent(*aPresContext, &mEvent, nsnull, DOM_EVENT_INIT, mStatus);
mFormFrame->OnReset();
}
else if ((NS_FORM_INPUT_SUBMIT == type) ||
((NS_FORM_INPUT_IMAGE == type) && !nsFormFrame::GetDisabled(this))) {
//Send DOM event
nsEventStatus mStatus;
nsEvent mEvent;
mEvent.eventStructType = NS_EVENT;
mEvent.message = NS_FORM_SUBMIT;
mContent->HandleDOMEvent(*aPresContext, &mEvent, nsnull, DOM_EVENT_INIT, mStatus);
if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) {
nsEventStatus status;
nsEvent event;
event.eventStructType = NS_EVENT;
mFormFrame->OnSubmit(aPresContext, this);
switch(type) {
case NS_FORM_INPUT_BUTTON:
event.message = NS_MOUSE_LEFT_CLICK;
mContent->HandleDOMEvent(*aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
break;
case NS_FORM_INPUT_RESET:
event.message = NS_FORM_RESET;
mContent->HandleDOMEvent(*aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
if (nsEventStatus_eConsumeNoDefault != status) {
mFormFrame->OnReset();
}
break;
case NS_FORM_INPUT_SUBMIT:
event.message = NS_FORM_SUBMIT;
mContent->HandleDOMEvent(*aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
if (nsEventStatus_eConsumeNoDefault != status) {
mFormFrame->OnSubmit(aPresContext, this);
}
}
} else if ((NS_FORM_BROWSE == type) && mFileControlFrame) {
mFileControlFrame->MouseClicked(aPresContext);
@ -306,28 +294,6 @@ nsButtonControlFrame::Reflow(nsIPresContext& aPresContext,
}
}
// XXX This is a copy of the code in nsImageFrame.cpp
static nsresult
UpdateImageFrame(nsIPresContext& aPresContext, nsIFrame* aFrame,
PRIntn aStatus)
{
if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
// Now that the size is available, trigger a content-changed reflow
nsIContent* content = nsnull;
aFrame->GetContent(content);
if (nsnull != content) {
nsIDocument* document = nsnull;
content->GetDocument(document);
if (nsnull != document) {
document->ContentChanged(content, nsnull);
NS_RELEASE(document);
}
NS_RELEASE(content);
}
}
return NS_OK;
}
void
nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
@ -343,35 +309,25 @@ nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
aDesiredLayoutSize.ascent = 0;
aDesiredLayoutSize.descent = 0;
} else {
if (NS_FORM_INPUT_IMAGE == type) { // there is an image
// Setup url before starting the image load
nsAutoString src;
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("SRC", src)) {
mImageLoader.SetURL(src);
}
mImageLoader.GetDesiredSize(aPresContext, aReflowState, this, UpdateImageFrame,
aDesiredLayoutSize);
} else { // there is a widget
nsSize styleSize;
GetStyleSize(*aPresContext, aReflowState, styleSize);
// a browse button shares is style context with its parent nsInputFile
// it uses everything from it except width
if (NS_FORM_BROWSE == type) {
styleSize.width = CSS_NOTSET;
}
nsSize size;
PRBool widthExplicit, heightExplicit;
PRInt32 ignore;
nsAutoString defaultLabel;
GetDefaultLabel(defaultLabel);
nsInputDimensionSpec spec(nsHTMLAtoms::size, PR_TRUE, nsHTMLAtoms::value,
&defaultLabel, 1, PR_FALSE, nsnull, 1);
CalculateSize(aPresContext, this, styleSize, spec, size,
widthExplicit, heightExplicit, ignore,
aReflowState.rendContext);
aDesiredLayoutSize.width = size.width;
aDesiredLayoutSize.height= size.height;
nsSize styleSize;
GetStyleSize(*aPresContext, aReflowState, styleSize);
// a browse button shares is style context with its parent nsInputFile
// it uses everything from it except width
if (NS_FORM_BROWSE == type) {
styleSize.width = CSS_NOTSET;
}
nsSize size;
PRBool widthExplicit, heightExplicit;
PRInt32 ignore;
nsAutoString defaultLabel;
GetDefaultLabel(defaultLabel);
nsInputDimensionSpec spec(nsHTMLAtoms::size, PR_TRUE, nsHTMLAtoms::value,
&defaultLabel, 1, PR_FALSE, nsnull, 1);
CalculateSize(aPresContext, this, styleSize, spec, size,
widthExplicit, heightExplicit, ignore,
aReflowState.rendContext);
aDesiredLayoutSize.width = size.width;
aDesiredLayoutSize.height= size.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
}

Просмотреть файл

@ -20,7 +20,6 @@
#define nsButtonControlFrame_h___
#include "nsFormControlFrame.h"
#include "nsHTMLImage.h"
class nsFileControlFrame;
class nsButtonControlFrame : public nsFormControlFrame {
@ -36,6 +35,11 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
@ -72,7 +76,6 @@ protected:
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
nsHTMLImageLoader mImageLoader;
nsFileControlFrame* mFileControlFrame; // for browse buttons only
};

Просмотреть файл

@ -44,6 +44,11 @@ public:
nscoord& aWidth,
nscoord& aHeight);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual const nsIID& GetCID();
virtual const nsIID& GetIID();
@ -165,6 +170,32 @@ nsCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord&
}
}
NS_IMETHODIMP
nsCheckboxControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
if (mWidget) {
if (nsHTMLAtoms::checked == aAttribute) {
nsICheckButton* button = nsnull;
result = mWidget->QueryInterface(GetIID(), (void**)&button);
if ((NS_SUCCEEDED(result)) && (nsnull != button)) {
PRBool checkedAttr;
GetChecked(&checkedAttr);
PRBool checkedPrevState;
button->GetState(checkedPrevState);
if (checkedAttr != checkedPrevState) {
button->SetState(checkedAttr);
}
NS_RELEASE(button);
}
}
}
return result;
}
void
nsCheckboxControlFrame::MouseClicked(nsIPresContext* aPresContext)
{

Просмотреть файл

@ -312,6 +312,15 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext,
return NS_OK;
}
NS_IMETHODIMP
nsFormControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
return NS_OK;
}
nsWidgetInitData*
nsFormControlFrame::GetWidgetInitData(nsIPresContext& aPresContext)
{

Просмотреть файл

@ -125,6 +125,10 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
// new behavior
/**

Просмотреть файл

@ -47,6 +47,8 @@
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMNSHTMLFormElement.h"
#include "nsLeafFrame.h"
#include "nsHTMLParts.h"
#include "nsIReflowCommand.h"
#include "net.h"
#include "xp_file.h"
@ -333,7 +335,7 @@ void nsFormFrame::AddFormControlFrame(nsIFormControlFrame& aFrame)
}
void
nsFormFrame::OnRadioChecked(nsRadioControlFrame& aControl)
nsFormFrame::OnRadioChecked(nsRadioControlFrame& aControl, PRBool aChecked)
{
nsString radioName;
aControl.GetName(&radioName);
@ -348,11 +350,17 @@ nsFormFrame::OnRadioChecked(nsRadioControlFrame& aControl)
nsString groupName;
group->GetName(groupName);
nsRadioControlFrame* checkedRadio = group->GetCheckedRadio();
if (groupName.Equals(radioName) && (&aControl != checkedRadio)) {
if (checkedRadio) {
if (groupName.Equals(radioName)) {
if (aChecked) {
if (&aControl != checkedRadio) {
if (checkedRadio) {
checkedRadio->SetChecked(PR_FALSE, PR_FALSE);
}
group->SetCheckedRadio(&aControl);
}
} else if (&aControl == checkedRadio) {
checkedRadio->SetChecked(PR_FALSE, PR_FALSE);
}
group->SetCheckedRadio(&aControl);
}
}
}
@ -1068,3 +1076,80 @@ nsFormFrame::GetReadonly(nsIFrame* aChildFrame, nsIContent* aContent)
}
return result;
}
nsresult
nsFormFrame::GetName(nsIFrame* aChildFrame, nsString& aName, nsIContent* aContent)
{
nsresult result = NS_FORM_NOTOK;
nsIContent* content = aContent;
if (nsnull == content) {
aChildFrame->GetContent(content);
}
if (nsnull != content) {
nsIHTMLContent* htmlContent = nsnull;
result = content->QueryInterface(kIHTMLContentIID, (void**)&htmlContent);
if (NS_SUCCEEDED(result) && (nsnull != htmlContent)) {
nsHTMLValue value;
result = htmlContent->GetAttribute(nsHTMLAtoms::name, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (eHTMLUnit_String == value.GetUnit()) {
value.GetStringValue(aName);
}
}
NS_RELEASE(htmlContent);
}
if (nsnull == aContent) {
NS_RELEASE(content);
}
}
return result;
}
nsresult
nsFormFrame::GetValue(nsIFrame* aChildFrame, nsString& aValue, nsIContent* aContent)
{
nsresult result = NS_FORM_NOTOK;
nsIContent* content = aContent;
if (nsnull == content) {
aChildFrame->GetContent(content);
}
if (nsnull != content) {
nsIHTMLContent* htmlContent = nsnull;
result = content->QueryInterface(kIHTMLContentIID, (void**)&htmlContent);
if (NS_SUCCEEDED(result) && (nsnull != htmlContent)) {
nsHTMLValue value;
result = htmlContent->GetAttribute(nsHTMLAtoms::value, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (eHTMLUnit_String == value.GetUnit()) {
value.GetStringValue(aValue);
}
}
NS_RELEASE(htmlContent);
}
if (nsnull == aContent) {
NS_RELEASE(content);
}
}
return result;
}
void
nsFormFrame::StyleChangeReflow(nsIPresContext* aPresContext,
nsIFrame* aFrame)
{
nsIPresShell* shell;
shell = aPresContext->GetShell();
nsIReflowCommand* reflowCmd;
nsresult rv = NS_NewHTMLReflowCommand(&reflowCmd, aFrame,
nsIReflowCommand::StyleChanged);
if (NS_SUCCEEDED(rv)) {
shell->AppendReflowCommand(reflowCmd);
NS_RELEASE(reflowCmd);
}
NS_RELEASE(shell);
}

Просмотреть файл

@ -97,7 +97,7 @@ public:
// other methods
void OnRadioChecked(nsRadioControlFrame& aRadio);
void OnRadioChecked(nsRadioControlFrame& aRadio, PRBool aChecked = PR_TRUE);
void AddFormControlFrame(nsIFormControlFrame& aFrame);
static void AddFormControlFrame(nsIPresContext& aPresContext, nsIFrame& aFrame);
@ -122,6 +122,10 @@ public:
static PRBool GetDisabled(nsIFrame* aChildFrame, nsIContent* aContent = 0);
static PRBool GetReadonly(nsIFrame* aChildFrame, nsIContent* aContent = 0);
static nsresult GetName(nsIFrame* aChildFrame, nsString& aName, nsIContent* aContent = 0);
static nsresult GetValue(nsIFrame* aChildFrame, nsString& aValue, nsIContent* aContent = 0);
static void StyleChangeReflow(nsIPresContext* aPresContext,
nsIFrame* aFrame);
protected:
NS_IMETHOD_(nsrefcnt) AddRef(void);

Просмотреть файл

@ -0,0 +1,395 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsHTMLImage.h"
#include "nsIFormControlFrame.h"
#include "nsIFormControl.h"
#include "nsHTMLParts.h"
#include "nsIRenderingContext.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIStyleContext.h"
#include "nsLeafFrame.h"
#include "nsCSSRendering.h"
#include "nsHTMLIIDs.h"
#include "nsIViewManager.h"
#include "nsISupports.h"
#include "nsHTMLAtoms.h"
#include "nsIView.h"
#include "nsViewsCID.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsIImage.h"
#include "nsStyleUtil.h"
#include "nsDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIHTMLAttributes.h"
#include "nsGenericHTMLElement.h"
#include "nsFormFrame.h"
//Enumeration of possible mouse states used to detect mouse clicks
enum nsMouseState {
eMouseNone,
eMouseEnter,
eMouseDown,
eMouseExit
};
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
class nsImageControlFrame : public ImageFrame,
public nsIFormControlFrame
{
public:
nsImageControlFrame(nsIContent* aContent, nsIFrame* aParentFrame);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD Init(nsIPresContext& aPresContext, nsIFrame* aChildList);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
virtual void MouseClicked(nsIPresContext* aPresContext);
virtual void SetFormFrame(nsFormFrame* aFormFrame) { mFormFrame = aFormFrame; }
PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
virtual PRInt32 GetMaxNumValues();
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
NS_IMETHOD GetType(PRInt32* aType) const;
NS_IMETHOD GetName(nsString* aName);
virtual void Reset() {};
void SetFocus(PRBool aOn, PRBool aRepaint);
protected:
virtual ~nsImageControlFrame();
void GetTranslatedRect(nsRect& aRect); // XXX this implementation is a copy of nsHTMLButtonControlFrame
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
nsFormFrame* mFormFrame;
nsMouseState mLastMouseState;
nsPoint mLastClickPoint;
nsCursor mPreviousCursor;
nsRect mTranslatedRect;
PRBool mGotFocus;
};
nsImageControlFrame::nsImageControlFrame(nsIContent* aContent,
nsIFrame* aParentFrame)
: ImageFrame(aContent, aParentFrame)
{
mLastMouseState = eMouseNone;
mLastClickPoint = nsPoint(0,0);
mPreviousCursor = eCursor_standard;
mTranslatedRect = nsRect(0,0,0,0);
mGotFocus = PR_FALSE;
}
nsImageControlFrame::~nsImageControlFrame()
{
}
nsresult
NS_NewImageControlFrame(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame*& aResult)
{
aResult = new nsImageControlFrame(aContent, aParent);
if (nsnull == aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
nsresult
nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIFormControlFrameIID)) {
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
return NS_OK;
}
return ImageFrame::QueryInterface(aIID, aInstancePtr);
}
nsrefcnt nsImageControlFrame::AddRef(void)
{
NS_WARNING("not supported");
return 1;
}
nsrefcnt nsImageControlFrame::Release(void)
{
NS_WARNING("not supported");
return 1;
}
NS_IMETHODIMP
nsImageControlFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList)
{
nsFormFrame::AddFormControlFrame(aPresContext, *this);
if (nsnull == mFormFrame) {
return NS_OK;
}
// add ourself as an nsIFormControlFrame
nsFormFrame::AddFormControlFrame(aPresContext, *this);
// create our view, we need a view to grab the mouse
nsIView* view;
GetView(view);
if (!view) {
nsresult result = nsRepository::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&view);
nsIPresShell *presShell = aPresContext.GetShell();
nsIViewManager *viewMan = presShell->GetViewManager();
NS_RELEASE(presShell);
nsIFrame* parWithView;
nsIView *parView;
GetParentWithView(parWithView);
parWithView->GetView(parView);
// the view's size is not know yet, but its size will be kept in synch with our frame.
nsRect boundBox(0, 0, 500, 500);
result = view->Init(viewMan, boundBox, parView, nsnull);
viewMan->InsertChild(parView, view, 0);
SetView(view);
const nsStyleColor* color = (const nsStyleColor*) mStyleContext->GetStyleData(eStyleStruct_Color);
// set the opacity
viewMan->SetViewOpacity(view, color->mOpacity);
NS_RELEASE(viewMan);
}
return NS_OK;
}
NS_METHOD
nsImageControlFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if (nsFormFrame::GetDisabled(this)) { // XXX cache disabled
return NS_OK;
}
aEventStatus = nsEventStatus_eIgnore;
nsresult result = NS_OK;
nsIView* view;
GetView(view);
if (view) {
nsIViewManager* viewMan;
view->GetViewManager(viewMan);
if (viewMan) {
nsIView* grabber;
viewMan->GetMouseEventGrabber(grabber);
if ((grabber == view) || (nsnull == grabber)) {
nsIWidget* window;
PRBool ignore;
switch (aEvent->message) {
case NS_MOUSE_ENTER: // not implemented yet on frames, 1st mouse move simulates it
mLastMouseState = eMouseEnter;
break;
case NS_MOUSE_LEFT_BUTTON_DOWN:
mLastMouseState = eMouseDown;
mGotFocus = PR_TRUE;
break;
case NS_MOUSE_MOVE:
//printf ("%d mRect=(%d,%d,%d,%d), x=%d, y=%d \n", foo++, mRect.x, mRect.y, mRect.width, mRect.height, aEvent->point.x, aEvent->point.y);
if (nsnull == grabber) { // simulated mouse enter
GetTranslatedRect(mTranslatedRect);
//printf("%d enter\n", foo++);
viewMan->GrabMouseEvents(view, ignore);
GetWindow(window);
if (window) {
mPreviousCursor = window->GetCursor();
window->SetCursor(eCursor_select); // set it to something else to work around bug
window->SetCursor(eCursor_standard);
NS_RELEASE(window);
}
mLastMouseState = eMouseEnter;
// simulated mouse exit
} else if (!mTranslatedRect.Contains(aEvent->point)) {
viewMan->GrabMouseEvents(nsnull, ignore);
GetWindow(window);
if (window) {
window->SetCursor(mPreviousCursor);
NS_RELEASE(window);
}
mLastMouseState = eMouseExit;
}
break;
case NS_MOUSE_LEFT_BUTTON_UP:
{
if (eMouseDown == mLastMouseState) {
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_MOUSE_EVENT;
event.message = NS_MOUSE_LEFT_CLICK;
mContent->HandleDOMEvent(aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
float t2p = aPresContext.GetTwipsToPixels();
mLastClickPoint.x = NSTwipsToIntPixels(aEvent->point.x - mTranslatedRect.x, t2p);
mLastClickPoint.y = NSTwipsToIntPixels(aEvent->point.y - mTranslatedRect.y, t2p);
if (nsEventStatus_eConsumeNoDefault != status) {
MouseClicked(&aPresContext);
}
mLastMouseState = eMouseEnter;
}
break;
}
case NS_MOUSE_EXIT: // doesn't work for frames, yet
break;
}
aEventStatus = nsEventStatus_eConsumeNoDefault;
NS_RELEASE(viewMan);
return NS_OK;
}
}
}
return ImageFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
void
nsImageControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
{
mGotFocus = aOn;
if (aRepaint) {
nsRect rect(0, 0, mRect.width, mRect.height);
Invalidate(rect, PR_TRUE);
}
}
void
nsImageControlFrame::GetTranslatedRect(nsRect& aRect)
{
nsIView* view;
nsPoint viewOffset(0,0);
GetOffsetFromView(viewOffset, view);
while (nsnull != view) {
nsPoint tempOffset;
view->GetPosition(&tempOffset.x, &tempOffset.y);
viewOffset += tempOffset;
view->GetParent(view);
}
aRect = nsRect(viewOffset.x, viewOffset.y, mRect.width, mRect.height);
}
NS_IMETHODIMP
nsImageControlFrame::GetType(PRInt32* aType) const
{
*aType = NS_FORM_INPUT_IMAGE;
return NS_OK;
}
NS_IMETHODIMP
nsImageControlFrame::GetName(nsString* aResult)
{
if (nsnull == aResult) {
return NS_OK;
} else {
return nsFormFrame::GetName(this, *aResult);
}
}
PRBool
nsImageControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
if (this == (aSubmitter)) {
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
return PR_FALSE;
}
PRInt32
nsImageControlFrame::GetMaxNumValues()
{
return 2;
}
PRBool
nsImageControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)
{
nsAutoString name;
nsresult result = GetName(&name);
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_HAS_VALUE != result)) {
return PR_FALSE;
}
nsAutoString value;
nsresult valResult = nsFormFrame::GetValue(this, value);
char buf[20];
aNumValues = 2;
aValues[0].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.x);
aValues[0].Append(&buf[0]);
aNames[0] = name;
aNames[0].Append(".x");
aValues[1].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.y);
aValues[1].Append(&buf[0]);
aNames[1] = name;
aNames[1].Append(".y");
return PR_TRUE;
}
void
nsImageControlFrame::MouseClicked(nsIPresContext* aPresContext)
{
PRInt32 type;
GetType(&type);
if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) {
nsEventStatus status;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SUBMIT;
mContent->HandleDOMEvent(*aPresContext, &event, nsnull, DOM_EVENT_INIT, status);
if (nsEventStatus_eConsumeNoDefault != status) {
mFormFrame->OnSubmit(aPresContext, this);
}
}
}

Просмотреть файл

@ -57,15 +57,10 @@ NS_NewRadioControlFrame(nsIContent* aContent,
nsRadioControlFrame::nsRadioControlFrame(nsIContent* aContent, nsIFrame* aParentFrame)
: nsFormControlFrame(aContent, aParentFrame)
{
mInitialChecked = nsnull;
mForcedChecked = PR_FALSE;
}
nsRadioControlFrame::~nsRadioControlFrame()
{
if (mInitialChecked) {
delete mInitialChecked;
}
}
const nsIID&
@ -101,7 +96,7 @@ nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWi
{
nsIRadioButton* radio = nsnull;
if (mWidget && (NS_OK == mWidget->QueryInterface(GetIID(),(void**)&radio))) {
radio->SetState(mForcedChecked);
radio->SetState(GetChecked(PR_TRUE));
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
@ -117,6 +112,31 @@ nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWi
}
NS_IMETHODIMP
nsRadioControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
if (mWidget) {
if (nsHTMLAtoms::checked == aAttribute) {
nsIRadioButton* button = nsnull;
result = mWidget->QueryInterface(kIRadioIID, (void**)&button);
if ((NS_SUCCEEDED(result)) && (nsnull != button)) {
PRBool checkedAttr = GetChecked(PR_TRUE);
PRBool checkedPrevState = GetChecked(PR_FALSE);
if (checkedAttr != checkedPrevState) {
button->SetState(checkedAttr);
mFormFrame->OnRadioChecked(*this, checkedAttr);
}
NS_RELEASE(button);
}
}
}
return result;
}
void
nsRadioControlFrame::MouseClicked(nsIPresContext* aPresContext)
{
@ -134,21 +154,19 @@ PRBool
nsRadioControlFrame::GetChecked(PRBool aGetInitialValue)
{
if (aGetInitialValue) {
if (!mInitialChecked && mContent) {
mInitialChecked = new PRBool(PR_FALSE);
if (mContent) {
nsIHTMLContent* iContent = nsnull;
nsresult result = mContent->QueryInterface(kIHTMLContentIID, (void**)&iContent);
if ((NS_OK == result) && iContent) {
nsHTMLValue value;
result = iContent->GetAttribute(nsHTMLAtoms::checked, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
*mInitialChecked = PR_TRUE;
mForcedChecked = PR_TRUE;
return PR_TRUE;
}
NS_RELEASE(iContent);
}
}
return *mInitialChecked;
return PR_FALSE;
}
PRBool result = PR_FALSE;
@ -157,7 +175,7 @@ nsRadioControlFrame::GetChecked(PRBool aGetInitialValue)
radio->GetState(result);
NS_RELEASE(radio);
} else {
result = mForcedChecked;
result = GetChecked(PR_TRUE);
}
return result;
}
@ -165,12 +183,12 @@ nsRadioControlFrame::GetChecked(PRBool aGetInitialValue)
void
nsRadioControlFrame::SetChecked(PRBool aValue, PRBool aSetInitialValue)
{
mForcedChecked = aValue;
if (aSetInitialValue) {
if (!mInitialChecked) {
mInitialChecked = new PRBool(aValue);
if (aValue) {
mContent->SetAttribute("checked", "1", PR_FALSE);
} else {
mContent->SetAttribute("checked", "0", PR_FALSE);
}
*mInitialChecked = aValue;
}
nsIRadioButton* radio = nsnull;
if (mWidget && (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio))) {
@ -220,8 +238,7 @@ nsRadioControlFrame::Reset()
{
nsIRadioButton* radio = nsnull;
if (mWidget && (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio))) {
PRBool state = (nsnull == mInitialChecked) ? PR_FALSE : *mInitialChecked;
radio->SetState(state);
radio->SetState(GetChecked(PR_TRUE));
NS_RELEASE(radio);
}
}

Просмотреть файл

@ -35,6 +35,11 @@ public:
nscoord& aWidth,
nscoord& aHeight);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual PRBool GetChecked(PRBool aGetInitialValue);
virtual void SetChecked(PRBool aValue, PRBool aSetInitialValue);
@ -57,8 +62,6 @@ protected:
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
PRBool *mInitialChecked;
PRBool mForcedChecked;
};
// nsRadioControlGroup

Просмотреть файл

@ -264,7 +264,7 @@ nsTextControlFrame::GetText(nsString* aText)
nsIDOMHTMLInputElement* textElem = nsnull;
result = mContent->QueryInterface(kIDOMHTMLInputElementIID, (void**)&textElem);
if ((NS_OK == result) && textElem) {
result = textElem->GetValue(*aText);
result = textElem->GetDefaultValue(*aText);
NS_RELEASE(textElem);
}
} else {
@ -278,6 +278,41 @@ nsTextControlFrame::GetText(nsString* aText)
return result;
}
NS_IMETHODIMP
nsTextControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
PRInt32 type;
GetType(&type);
if (mWidget) {
nsITextWidget* text = nsnull;
result = mWidget->QueryInterface(kITextWidgetIID, (void**)&text);
if ((NS_SUCCEEDED(result)) && (nsnull != text)) {
if (nsHTMLAtoms::value == aAttribute) {
nsString value;
nsresult result = GetText(&value);
PRUint32 ignore;
text->SetText(value, ignore);
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
} else if (nsHTMLAtoms::size == aAttribute) {
nsFormFrame::StyleChangeReflow(aPresContext, this);
} else if (nsHTMLAtoms::maxlength == aAttribute) {
PRInt32 maxLength;
nsresult result = GetMaxLength(&maxLength);
if (NS_CONTENT_ATTR_NOT_THERE != result) {
text->SetMaxTextLength(maxLength);
}
}
NS_RELEASE(text);
}
return result;
}
void
nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
@ -298,19 +333,7 @@ nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext,
PRUint32 ignore;
nsAutoString value;
// XXX Workaround for "text" input elements not initializing their widget
// to the initial value. See http://www.cnet.com
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
// Use the default value, because the widget has just been created and
// we're setting its initial value
nsIDOMHTMLInputElement* textElem = nsnull;
if (NS_SUCCEEDED(mContent->QueryInterface(kIDOMHTMLInputElementIID, (void**)&textElem))) {
textElem->GetDefaultValue(value);
NS_RELEASE(textElem);
}
} else {
GetText(&value);
}
GetText(&value);
nsITextAreaWidget* textArea = nsnull;
nsITextWidget* text = nsnull;

Просмотреть файл

@ -30,6 +30,11 @@ public:
virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext& aPresContext);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);

Просмотреть файл

@ -41,13 +41,14 @@
#include "nsIViewManager.h"
#include "nsStyleConsts.h"
#include "nsTableOuterFrame.h"
#include "nsIWebShell.h"
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
class HTMLAnchorRule : public nsIStyleRule {
public:
@ -331,9 +332,10 @@ protected:
nsIFrame* aParentFrame,
nsIFrame*& aFrame);
PRBool IsScrollable(const nsStyleDisplay* aDisplay);
PRBool IsScrollable(nsIPresContext* aPresContext, const nsStyleDisplay* aDisplay);
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent);
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
nsIContent* aContent);
PRBool AttributeRequiresRepaint(nsIAtom* aAttribute);
PRBool AttributeRequiresReflow (nsIAtom* aAttribute);
@ -903,7 +905,7 @@ HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent,
rv = NS_NewButtonControlFrame(aContent, aParentFrame, aFrame);
}
else if (val.EqualsIgnoreCase("image")) {
rv = NS_NewButtonControlFrame(aContent, aParentFrame, aFrame);
rv = NS_NewImageControlFrame(aContent, aParentFrame, aFrame);
}
else if (val.EqualsIgnoreCase("password")) {
rv = NS_NewTextControlFrame(aContent, aParentFrame, aFrame);
@ -1383,12 +1385,30 @@ HTMLStyleSheetImpl::GetAdjustedParentFrame(nsIFrame* aCurrentParentFrame,
}
PRBool
HTMLStyleSheetImpl::IsScrollable(const nsStyleDisplay* aDisplay)
HTMLStyleSheetImpl::IsScrollable(nsIPresContext* aPresContext, const nsStyleDisplay* aDisplay)
{
// For the time being it's scrollable if the overflow property is auto or
// scroll, regardless of whether the width or height is fixed in size
if ((NS_STYLE_OVERFLOW_SCROLL == aDisplay->mOverflow) ||
(NS_STYLE_OVERFLOW_AUTO == aDisplay->mOverflow)) {
PRInt32 scrolling = -1;
nsISupports* container;
if (nsnull != aPresContext) {
aPresContext->GetContainer(&container);
if (nsnull != container) {
nsIWebShell* webShell = nsnull;
container->QueryInterface(kIWebShellIID, (void**) &webShell);
if (nsnull != webShell) {
webShell->GetScrolling(scrolling);
NS_RELEASE(webShell);
}
NS_RELEASE(container);
}
}
if (-1 == scrolling) {
scrolling = aDisplay->mOverflow;
}
if ((NS_STYLE_OVERFLOW_SCROLL == scrolling) ||
(NS_STYLE_OVERFLOW_AUTO == scrolling)) {
return PR_TRUE;
}
@ -1457,7 +1477,7 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
// If we're paginated then don't ever make the BODY scrollable
// XXX Use a special BODY rule for paged media
if (!(aPresContext->IsPaginated() && (nsHTMLAtoms::body == tag))) {
if (display->IsBlockLevel() && IsScrollable(display)) {
if (display->IsBlockLevel() && IsScrollable(aPresContext, display)) {
// Create a scroll frame which will wrap the frame that needs to
// be scrolled
if NS_SUCCEEDED(NS_NewScrollFrame(aContent, aParentFrame, scrollFrame)) {
@ -1504,7 +1524,8 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
}
nsIFrame*
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent)
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
nsIContent* aContent)
{
nsIFrame* frame = aPresShell->FindFrameWithContent(aContent);
@ -1514,7 +1535,7 @@ HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent)
const nsStyleDisplay* display;
frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->IsBlockLevel() && IsScrollable(display)) {
if (display->IsBlockLevel() && IsScrollable(aPresContext, display)) {
frame->FirstChild(nsnull, frame);
}
}
@ -1528,7 +1549,7 @@ HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,
PRInt32 aNewIndexInContainer)
{
nsIPresShell* shell = aPresContext->GetShell();
nsIFrame* parentFrame = GetFrameFor(shell, aContainer);
nsIFrame* parentFrame = GetFrameFor(shell, aPresContext, aContainer);
#ifdef NS_DEBUG
if (nsnull == parentFrame) {

Просмотреть файл

@ -41,13 +41,14 @@
#include "nsIViewManager.h"
#include "nsStyleConsts.h"
#include "nsTableOuterFrame.h"
#include "nsIWebShell.h"
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
class HTMLAnchorRule : public nsIStyleRule {
public:
@ -331,9 +332,10 @@ protected:
nsIFrame* aParentFrame,
nsIFrame*& aFrame);
PRBool IsScrollable(const nsStyleDisplay* aDisplay);
PRBool IsScrollable(nsIPresContext* aPresContext, const nsStyleDisplay* aDisplay);
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent);
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
nsIContent* aContent);
PRBool AttributeRequiresRepaint(nsIAtom* aAttribute);
PRBool AttributeRequiresReflow (nsIAtom* aAttribute);
@ -903,7 +905,7 @@ HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent,
rv = NS_NewButtonControlFrame(aContent, aParentFrame, aFrame);
}
else if (val.EqualsIgnoreCase("image")) {
rv = NS_NewButtonControlFrame(aContent, aParentFrame, aFrame);
rv = NS_NewImageControlFrame(aContent, aParentFrame, aFrame);
}
else if (val.EqualsIgnoreCase("password")) {
rv = NS_NewTextControlFrame(aContent, aParentFrame, aFrame);
@ -1383,12 +1385,30 @@ HTMLStyleSheetImpl::GetAdjustedParentFrame(nsIFrame* aCurrentParentFrame,
}
PRBool
HTMLStyleSheetImpl::IsScrollable(const nsStyleDisplay* aDisplay)
HTMLStyleSheetImpl::IsScrollable(nsIPresContext* aPresContext, const nsStyleDisplay* aDisplay)
{
// For the time being it's scrollable if the overflow property is auto or
// scroll, regardless of whether the width or height is fixed in size
if ((NS_STYLE_OVERFLOW_SCROLL == aDisplay->mOverflow) ||
(NS_STYLE_OVERFLOW_AUTO == aDisplay->mOverflow)) {
PRInt32 scrolling = -1;
nsISupports* container;
if (nsnull != aPresContext) {
aPresContext->GetContainer(&container);
if (nsnull != container) {
nsIWebShell* webShell = nsnull;
container->QueryInterface(kIWebShellIID, (void**) &webShell);
if (nsnull != webShell) {
webShell->GetScrolling(scrolling);
NS_RELEASE(webShell);
}
NS_RELEASE(container);
}
}
if (-1 == scrolling) {
scrolling = aDisplay->mOverflow;
}
if ((NS_STYLE_OVERFLOW_SCROLL == scrolling) ||
(NS_STYLE_OVERFLOW_AUTO == scrolling)) {
return PR_TRUE;
}
@ -1457,7 +1477,7 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
// If we're paginated then don't ever make the BODY scrollable
// XXX Use a special BODY rule for paged media
if (!(aPresContext->IsPaginated() && (nsHTMLAtoms::body == tag))) {
if (display->IsBlockLevel() && IsScrollable(display)) {
if (display->IsBlockLevel() && IsScrollable(aPresContext, display)) {
// Create a scroll frame which will wrap the frame that needs to
// be scrolled
if NS_SUCCEEDED(NS_NewScrollFrame(aContent, aParentFrame, scrollFrame)) {
@ -1504,7 +1524,8 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
}
nsIFrame*
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent)
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
nsIContent* aContent)
{
nsIFrame* frame = aPresShell->FindFrameWithContent(aContent);
@ -1514,7 +1535,7 @@ HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent)
const nsStyleDisplay* display;
frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->IsBlockLevel() && IsScrollable(display)) {
if (display->IsBlockLevel() && IsScrollable(aPresContext, display)) {
frame->FirstChild(nsnull, frame);
}
}
@ -1528,7 +1549,7 @@ HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,
PRInt32 aNewIndexInContainer)
{
nsIPresShell* shell = aPresContext->GetShell();
nsIFrame* parentFrame = GetFrameFor(shell, aContainer);
nsIFrame* parentFrame = GetFrameFor(shell, aPresContext, aContainer);
#ifdef NS_DEBUG
if (nsnull == parentFrame) {

Просмотреть файл

@ -24,6 +24,7 @@
#include "nsIScrollableView.h"
#include "nsIContentViewerContainer.h"
#include "nsILoadAttribs.h"
#include "nsIScrollableView.h"
class nsIFactory;
class nsIPostData;
@ -291,6 +292,8 @@ public:
NS_IMETHOD SetMarginWidth (PRInt32 aWidth) = 0;
NS_IMETHOD GetMarginHeight(PRInt32& aWidth) = 0;
NS_IMETHOD SetMarginHeight(PRInt32 aHeight) = 0;
NS_IMETHOD SetScrolling(PRInt32 aScrolling) = 0;
NS_IMETHOD GetScrolling(PRInt32& aScrolling) = 0;
/**
* Finds text in content

Просмотреть файл

@ -163,6 +163,8 @@ public:
NS_IMETHOD SetMarginWidth (PRInt32 aWidth);
NS_IMETHOD GetMarginHeight(PRInt32& aWidth);
NS_IMETHOD SetMarginHeight(PRInt32 aHeight);
NS_IMETHOD GetScrolling(PRInt32& aScrolling);
NS_IMETHOD SetScrolling(PRInt32 aScrolling);
// Document load api's
NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult);
@ -295,6 +297,7 @@ protected:
nsScrollPreference mScrollPref;
PRInt32 mMarginWidth;
PRInt32 mMarginHeight;
PRInt32 mScrolling;
nsVoidArray mRefreshments;
void ReleaseChildren();
@ -400,6 +403,7 @@ nsWebShell::nsWebShell()
mScriptContext = nsnull;
mMarginWidth = -1;
mMarginHeight = -1;
mScrolling = -1;
}
nsWebShell::~nsWebShell()
@ -609,7 +613,7 @@ nsWebShell::Init(nsNativeWidget aNativeParent,
CreatePluginHost(aAllowPlugins);
mScrollPref = aScrolling;
//mScrollPref = aScrolling;
WEB_TRACE(WEB_TRACE_CALLS,
("nsWebShell::Init: this=%p", this));
@ -1042,6 +1046,19 @@ nsWebShell::SetMarginHeight(PRInt32 aHeight)
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::GetScrolling(PRInt32& aScrolling)
{
aScrolling = mScrolling;
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetScrolling(PRInt32 aScrolling)
{
mScrolling = aScrolling;
return NS_OK;
}
/**
* Document Load methods
*/

Просмотреть файл

@ -199,6 +199,7 @@ install:: $(TARGETS)
$(INSTALL) samples/test8siz.html $(DIST)/bin/res/samples
$(INSTALL) samples/test8sca.html $(DIST)/bin/res/samples
$(INSTALL) samples/test8tab.html $(DIST)/bin/res/samples
$(INSTALL) samples/test8dom.html $(DIST)/bin/res/samples
$(INSTALL) samples/test9.html $(DIST)/bin/res/samples
$(INSTALL) samples/test9a.html $(DIST)/bin/res/samples
$(INSTALL) samples/test9b.html $(DIST)/bin/res/samples
@ -237,6 +238,7 @@ clobber::
rm -f $(DIST)/bin/res/samples/test8siz.html
rm -f $(DIST)/bin/res/samples/test8sca.html
rm -f $(DIST)/bin/res/samples/test8tab.html
rm -f $(DIST)/bin/res/samples/test8dom.html
rm -f $(DIST)/bin/res/samples/test9.html
rm -f $(DIST)/bin/res/samples/test9a.html
rm -f $(DIST)/bin/res/samples/test9b.html

Просмотреть файл

@ -106,6 +106,7 @@ install:: $(PROGRAM)
$(MAKE_INSTALL) samples\test8siz.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test8sca.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test8tab.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test8dom.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test_ed.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test9.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test9a.html $(DIST)\bin\res\samples
@ -145,6 +146,7 @@ clobber::
rm -f $(DIST)\bin\res\samples\test8siz.html
rm -f $(DIST)\bin\res\samples\test8sca.html
rm -f $(DIST)\bin\res\samples\test8tab.html
rm -f $(DIST)\bin\res\samples\test8dom.html
rm -f $(DIST)\bin\res\samples\test_ed.html
rm -f $(DIST)\bin\res\samples\test9.html
rm -f $(DIST)\bin\res\samples\test9a.html

Просмотреть файл

@ -124,6 +124,7 @@ Readonly controls
<HR>
Additional tests -&nbsp;
<A href=test8dom.html>changes through the DOM</A>,
<A href=test8siz.html>sizing</A>,
<A href=test8sca.html>scalability</A>,
<A href=test8tab.html>tables</A>

Просмотреть файл

@ -0,0 +1,69 @@
<html>
<body>
<form>
<input type=button value="change value attribute" onclick="changeValues(0)"> &nbsp;
<button onclick="changeSizes()">change size attribute</button>
<BR>
<input type=button value="change checked attribute" onclick="changeChecked()"> &nbsp;
<BR>
<input type=submit value=submit>
<input type=reset value=reset>
<input type=button value=button>
<INPUT type=image src=raptor.jpg width=50 height=50 name=imageSubmit value="js bug">
<BR>
<input type=checkbox checked value="js bug">
<input type=checkbox value="js bug">
<input type=radio name=radio checked value="js bug">
<input type=radio name=radio value="js bug">
<BR>
<button>html4 button</button>
<input type=text value=foo>
<textarea>foobar</textarea>
</form>
<script>
var numInputChangers = 2;
var inputs = document.getElementsByTagName("INPUT");
var numInputs = inputs.length;
var inputValues = new Array(numInputs+numInputs);
var start = numInputs;
var jsBug = 0;
for (var i = 0; i < numInputs; i++) {
inputValues[i] = inputs[i].value;
inputValues[numInputs+i] = "CHANGED"
}
function changeValues(aNativeChanger) {
if ((jsBug > 1) || (aNativeChanger == 1)) {
jsBug = 0;
if (start == 0) {
start = numInputs;
} else {
start = 0;
}
}
for (var i = numInputChangers; i < numInputs; i++) {
inputs[i].value = inputValues[start+i];
}
jsBug = jsBug + 1;
}
function changeSizes() {
inputs[2].size = 100;
inputs[3].size = 100;
inputs[4].size = 100;
inputs[11].size = 10;
}
function changeChecked() {
inputs[6].checked = false;
inputs[7].checked = true;
inputs[8].checked = false;
inputs[9].checked = true;
}
</script>
</body>
</html>