forked from rnewman/services-central-old
/
nsGenericHTMLElement.h
1407 lines (1251 loc) · 58.1 KB
/
nsGenericHTMLElement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsGenericHTMLElement_h___
#define nsGenericHTMLElement_h___
#include "nsMappedAttributeElement.h"
#include "nsIDOMHTMLElement.h"
#include "nsINameSpaceManager.h" // for kNameSpaceID_None
#include "nsIFormControl.h"
#include "nsIDOMNSHTMLFrameElement.h"
#include "nsFrameLoader.h"
#include "nsGkAtoms.h"
#include "nsContentCreatorFunctions.h"
class nsIDOMAttr;
class nsIDOMEventListener;
class nsIDOMNodeList;
class nsIFrame;
class nsIStyleRule;
class nsChildContentList;
class nsDOMCSSDeclaration;
class nsIDOMCSSStyleDeclaration;
class nsIURI;
class nsIFormControlFrame;
class nsIForm;
class nsPresState;
class nsILayoutHistoryState;
class nsIEditor;
struct nsRect;
struct nsSize;
class nsHTMLFormElement;
typedef nsMappedAttributeElement nsGenericHTMLElementBase;
/**
* A common superclass for HTML elements
*/
class nsGenericHTMLElement : public nsGenericHTMLElementBase
{
public:
nsGenericHTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsGenericHTMLElementBase(aNodeInfo)
{
NS_ASSERTION(mNodeInfo->NamespaceID() == kNameSpaceID_XHTML,
"Unexpected namespace");
}
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
static nsGenericHTMLElement* FromContent(nsIContent *aContent)
{
if (aContent->IsHTML())
return static_cast<nsGenericHTMLElement*>(aContent);
return nsnull;
}
/**
* Handle QI for the standard DOM interfaces (DOMNode, DOMElement,
* DOMHTMLElement) and handles tearoffs for other standard interfaces.
* @param aElement the element as nsIDOMHTMLElement*
* @param aIID the IID to QI to
* @param aInstancePtr the QI'd method [OUT]
* @see nsGenericHTMLElementTearoff
*/
nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement, REFNSIID aIID,
void **aInstancePtr);
// From nsGenericElement
nsresult CopyInnerTo(nsGenericElement* aDest) const;
// Implementation for nsIDOMNode
NS_METHOD GetNodeName(nsAString& aNodeName);
// Implementation for nsIDOMElement
NS_METHOD SetAttribute(const nsAString& aName,
const nsAString& aValue);
NS_METHOD GetTagName(nsAString& aTagName);
NS_METHOD GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn);
// nsIDOMHTMLElement methods. Note that these are non-virtual
// methods, implementations are expected to forward calls to these
// methods.
nsresult GetId(nsAString& aId);
nsresult SetId(const nsAString& aId);
nsresult GetTitle(nsAString& aTitle);
nsresult SetTitle(const nsAString& aTitle);
nsresult GetLang(nsAString& aLang);
nsresult SetLang(const nsAString& aLang);
nsresult GetDir(nsAString& aDir);
nsresult SetDir(const nsAString& aDir);
nsresult GetClassName(nsAString& aClassName);
nsresult SetClassName(const nsAString& aClassName);
// nsIDOMNSHTMLElement methods. Note that these are non-virtual
// methods, implementations are expected to forward calls to these
// methods.
nsresult GetOffsetTop(PRInt32* aOffsetTop);
nsresult GetOffsetLeft(PRInt32* aOffsetLeft);
nsresult GetOffsetWidth(PRInt32* aOffsetWidth);
nsresult GetOffsetHeight(PRInt32* aOffsetHeight);
nsresult GetOffsetParent(nsIDOMElement** aOffsetParent);
virtual nsresult GetInnerHTML(nsAString& aInnerHTML);
virtual nsresult SetInnerHTML(const nsAString& aInnerHTML);
nsresult ScrollIntoView(PRBool aTop, PRUint8 optional_argc);
// Declare Focus(), Blur(), GetTabIndex(), SetTabIndex(), GetHidden(),
// SetHidden(), GetSpellcheck(), SetSpellcheck(), and GetDraggable() such that
// classes that inherit interfaces with those methods properly override them.
NS_IMETHOD Focus();
NS_IMETHOD Blur();
NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
NS_IMETHOD GetHidden(PRBool* aHidden);
NS_IMETHOD SetHidden(PRBool aHidden);
NS_IMETHOD GetSpellcheck(PRBool* aSpellcheck);
NS_IMETHOD SetSpellcheck(PRBool aSpellcheck);
NS_IMETHOD GetDraggable(PRBool* aDraggable);
NS_IMETHOD SetDraggable(PRBool aDraggable);
nsresult GetContentEditable(nsAString &aContentEditable);
nsresult GetIsContentEditable(PRBool* aContentEditable);
nsresult SetContentEditable(const nsAString &aContentEditable);
// Implementation for nsIContent
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
PRBool aCompileEventHandlers);
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
PRBool aNullParent = PR_TRUE);
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
{
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
}
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify);
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
PRBool aNotify);
virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull, PRBool aWithMouse = PR_FALSE)
{
PRBool isFocusable = PR_FALSE;
IsHTMLFocusable(aWithMouse, &isFocusable, aTabIndex);
return isFocusable;
}
/**
* Returns PR_TRUE if a subclass is not allowed to override the value returned
* in aIsFocusable.
*/
virtual PRBool IsHTMLFocusable(PRBool aWithMouse,
PRBool *aIsFocusable,
PRInt32 *aTabIndex);
virtual void PerformAccesskey(PRBool aKeyCausesActivation,
PRBool aIsTrustedEvent);
/**
* Check if an event for an anchor can be handled
* @return PR_TRUE if the event can be handled, PR_FALSE otherwise
*/
PRBool CheckHandleEventForAnchorsPreconditions(nsEventChainVisitor& aVisitor);
nsresult PreHandleEventForAnchors(nsEventChainPreVisitor& aVisitor);
nsresult PostHandleEventForAnchors(nsEventChainPostVisitor& aVisitor);
PRBool IsHTMLLink(nsIURI** aURI) const;
// As above, but makes sure to return a URI object that we can mutate with
// impunity without changing our current URI. That is, if the URI is cached
// it clones it and returns the clone.
void GetHrefURIToMutate(nsIURI** aURI);
// HTML element methods
void Compact() { mAttrsAndChildren.Compact(); }
virtual void UpdateEditableState();
virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult);
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
/**
* Get the base target for any links within this piece
* of content. Generally, this is the document's base target,
* but certain content carries a local base for backward
* compatibility.
*
* @param aBaseTarget the base target [OUT]
*/
void GetBaseTarget(nsAString& aBaseTarget) const;
/**
* Get the primary form control frame for this element. Same as
* GetPrimaryFrame(), except it QI's to nsIFormControlFrame.
*
* @param aFlush whether to flush out frames so that they're up to date.
* @return the primary frame as nsIFormControlFrame
*/
nsIFormControlFrame* GetFormControlFrame(PRBool aFlushFrames);
//----------------------------------------
/**
* Parse an alignment attribute (top/middle/bottom/baseline)
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseAlignValue(const nsAString& aString,
nsAttrValue& aResult);
/**
* Parse a div align string to value (left/right/center/middle/justify)
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseDivAlignValue(const nsAString& aString,
nsAttrValue& aResult);
/**
* Convert a table halign string to value (left/right/center/char/justify)
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseTableHAlignValue(const nsAString& aString,
nsAttrValue& aResult);
/**
* Convert a table cell halign string to value
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseTableCellHAlignValue(const nsAString& aString,
nsAttrValue& aResult);
/**
* Convert a table valign string to value (left/right/center/char/justify/
* abscenter/absmiddle/middle)
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseTableVAlignValue(const nsAString& aString,
nsAttrValue& aResult);
/**
* Convert an image attribute to value (width, height, hspace, vspace, border)
*
* @param aAttribute the attribute to parse
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseImageAttribute(nsIAtom* aAttribute,
const nsAString& aString,
nsAttrValue& aResult);
/**
* Convert a frameborder string to value (yes/no/1/0)
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseFrameborderValue(const nsAString& aString,
nsAttrValue& aResult);
/**
* Convert a scrolling string to value (yes/no/on/off/scroll/noscroll/auto)
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue
* @return whether the value was parsed
*/
static PRBool ParseScrollingValue(const nsAString& aString,
nsAttrValue& aResult);
/*
* Attribute Mapping Helpers
*/
/**
* A style attribute mapping function for the most common attributes, to be
* called by subclasses' attribute mapping functions. Currently handles
* dir and lang, could handle others.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapCommonAttributesInto(const nsMappedAttributes* aAttributes,
nsRuleData* aRuleData);
static const MappedAttributeEntry sCommonAttributeMap[];
static const MappedAttributeEntry sImageMarginSizeAttributeMap[];
static const MappedAttributeEntry sImageBorderAttributeMap[];
static const MappedAttributeEntry sImageAlignAttributeMap[];
static const MappedAttributeEntry sDivAlignAttributeMap[];
static const MappedAttributeEntry sBackgroundAttributeMap[];
static const MappedAttributeEntry sBackgroundColorAttributeMap[];
static const MappedAttributeEntry sScrollingAttributeMap[];
/**
* Helper to map the align attribute into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapImageAlignAttributeInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the align attribute into a style struct for things
* like <div>, <h1>, etc.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapDivAlignAttributeInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the image border attribute into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapImageBorderAttributeInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the image margin attribute into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapImageMarginAttributeInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the image position attribute into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the background attribute
* into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapBackgroundInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the bgcolor attribute
* into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapBGColorInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the background attributes (currently background and bgcolor)
* into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Helper to map the scrolling attribute on FRAME and IFRAME
* into a style struct.
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
* @see GetAttributeMappingFunction
*/
static void MapScrollingAttributeInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData);
/**
* Get the presentation state for a piece of content, or create it if it does
* not exist. Generally used by SaveState().
*
* @param aContent the content to get presentation state for.
* @param aPresState the presentation state (out param)
*/
static nsresult GetPrimaryPresState(nsGenericHTMLElement* aContent,
nsPresState** aPresState);
/**
* Get the layout history object *and* generate the key for a particular
* piece of content.
*
* @param aContent the content to generate the key for
* @param aRead if true, won't return a layout history state (and won't
* generate a key) if the layout history state is empty.
* @param aState the history state object (out param)
* @param aKey the key (out param)
*/
static nsresult GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
PRBool aRead,
nsILayoutHistoryState** aState,
nsACString& aKey);
/**
* Restore the state for a form control. Ends up calling
* nsIFormControl::RestoreState().
*
* @param aContent an nsGenericHTMLElement* pointing to the form control
* @param aControl an nsIFormControl* pointing to the form control
* @return PR_FALSE if RestoreState() was not called, the return
* value of RestoreState() otherwise.
*/
static PRBool RestoreFormControlState(nsGenericHTMLElement* aContent,
nsIFormControl* aControl);
/**
* Get the presentation context for this content node.
* @return the presentation context
*/
NS_HIDDEN_(nsPresContext*) GetPresContext();
// Form Helper Routines
/**
* Find an ancestor of this content node which is a form (could be null)
* @param aCurrentForm the current form for this node. If this is
* non-null, and no ancestor form is found, and the current form is in
* a connected subtree with the node, the current form will be
* returned. This is needed to handle cases when HTML elements have a
* current form that they're not descendants of.
*/
nsHTMLFormElement* FindForm(nsHTMLFormElement* aCurrentForm = nsnull);
virtual void RecompileScriptEventListeners();
/**
* See if the document being tested has nav-quirks mode enabled.
* @param doc the document
*/
static PRBool InNavQuirksMode(nsIDocument* aDoc);
/**
* Locate an nsIEditor rooted at this content node, if there is one.
*/
NS_HIDDEN_(nsresult) GetEditor(nsIEditor** aEditor);
NS_HIDDEN_(nsresult) GetEditorInternal(nsIEditor** aEditor);
protected:
/**
* Add/remove this element to the documents name cache
*/
void AddToNameTable(nsIAtom* aName) {
NS_ASSERTION(HasFlag(NODE_HAS_NAME), "Node lacking NODE_HAS_NAME flag");
nsIDocument* doc = GetCurrentDoc();
if (doc && !IsInAnonymousSubtree()) {
doc->AddToNameTable(this, aName);
}
}
void RemoveFromNameTable() {
if (HasFlag(NODE_HAS_NAME)) {
nsIDocument* doc = GetCurrentDoc();
if (doc) {
doc->RemoveFromNameTable(this, GetParsedAttr(nsGkAtoms::name)->
GetAtomValue());
}
}
}
/**
* Register or unregister an access key to this element based on the
* accesskey attribute.
*/
void RegAccessKey()
{
if (HasFlag(NODE_HAS_ACCESSKEY)) {
RegUnRegAccessKey(PR_TRUE);
}
}
void UnregAccessKey()
{
if (HasFlag(NODE_HAS_ACCESSKEY)) {
RegUnRegAccessKey(PR_FALSE);
}
}
private:
void RegUnRegAccessKey(PRBool aDoReg);
protected:
/**
* Determine whether an attribute is an event (onclick, etc.)
* @param aName the attribute
* @return whether the name is an event handler name
*/
PRBool IsEventName(nsIAtom* aName);
virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify);
virtual nsresult
GetEventListenerManagerForAttr(nsIEventListenerManager** aManager,
nsISupports** aTarget,
PRBool* aDefer);
virtual const nsAttrName* InternalGetExistingAttrNameFromQName(const nsAString& aStr) const;
/**
* Helper method for NS_IMPL_STRING_ATTR macro.
* Gets the value of an attribute, returns empty string if
* attribute isn't set. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
* @param aResult result value [out]
* @result always NS_OK
*/
NS_HIDDEN_(nsresult) GetAttrHelper(nsIAtom* aAttr, nsAString& aValue);
/**
* Helper method for NS_IMPL_STRING_ATTR macro.
* Sets the value of an attribute, returns specified default value if the
* attribute isn't set. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) SetAttrHelper(nsIAtom* aAttr, const nsAString& aValue);
/**
* Helper method for NS_IMPL_STRING_ATTR_DEFAULT_VALUE macro.
* Gets the value of an attribute, returns specified default value if the
* attribute isn't set. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) GetStringAttrWithDefault(nsIAtom* aAttr,
const char* aDefault,
nsAString& aResult);
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.
* Gets value of boolean attribute. Only works for attributes in null
* namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
NS_HIDDEN_(nsresult) GetBoolAttr(nsIAtom* aAttr, PRBool* aValue) const;
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.
* Sets value of boolean attribute by removing attribute or setting it to
* the empty string. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
NS_HIDDEN_(nsresult) SetBoolAttr(nsIAtom* aAttr, PRBool aValue);
/**
* Helper method for NS_IMPL_INT_ATTR macro.
* Gets the integer-value of an attribute, returns specified default value
* if the attribute isn't set or isn't set to an integer. Only works for
* attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) GetIntAttr(nsIAtom* aAttr, PRInt32 aDefault, PRInt32* aValue);
/**
* Helper method for NS_IMPL_INT_ATTR macro.
* Sets value of attribute to specified integer. Only works for attributes
* in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Integer value of attribute.
*/
NS_HIDDEN_(nsresult) SetIntAttr(nsIAtom* aAttr, PRInt32 aValue);
/**
* Helper method for NS_IMPL_FLOAT_ATTR macro.
* Gets the float-value of an attribute, returns specified default value
* if the attribute isn't set or isn't set to a float. Only works for
* attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) GetFloatAttr(nsIAtom* aAttr, float aDefault, float* aValue);
/**
* Helper method for NS_IMPL_FLOAT_ATTR macro.
* Sets value of attribute to specified float. Only works for attributes
* in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Float value of attribute.
*/
NS_HIDDEN_(nsresult) SetFloatAttr(nsIAtom* aAttr, float aValue);
/**
* Helper method for NS_IMPL_URI_ATTR macro.
* Gets the absolute URI value of an attribute, by resolving any relative
* URIs in the attribute against the baseuri of the element. If the attribute
* isn't a relative URI the value of the attribute is returned as is. Only
* works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aBaseAttr name of base attribute.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsAString& aResult);
/**
* Helper for GetURIAttr and GetHrefURIForAnchors which returns an
* nsIURI in the out param.
*
* @param aCloneIfCached if true, clone the URI before returning if
* it's cached.
*
* @return PR_TRUE if we had the attr, PR_FALSE otherwise.
*/
NS_HIDDEN_(PRBool) GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr,
PRBool aCloneIfCached, nsIURI** aURI) const;
/**
* This method works like GetURIAttr, except that it supports multiple
* URIs separated by whitespace (one or more U+0020 SPACE characters).
*
* Gets the absolute URI values of an attribute, by resolving any relative
* URIs in the attribute against the baseuri of the element. If a substring
* isn't a relative URI, the substring is returned as is. Only works for
* attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) GetURIListAttr(nsIAtom* aAttr, nsAString& aResult);
/**
* Helper method for NS_IMPL_ENUM_ATTR_DEFAULT_VALUE.
* Gets the enum value string of an attribute and using a default value if
* the attribute is missing or the string is an invalid enum value.
*
* @param aType the name of the attribute.
* @param aDefault the default value if the attribute is missing or invalid.
* @param aResult string corresponding to the value [out].
*/
NS_HIDDEN_(nsresult) GetEnumAttr(nsIAtom* aAttr,
const char* aDefault,
nsAString& aResult);
/**
* Locates the nsIEditor associated with this node. In general this is
* equivalent to GetEditorInternal(), but for designmode or contenteditable,
* this may need to get an editor that's not actually on this element's
* associated TextControlFrame. This is used by the spellchecking routines
* to get the editor affected by changing the spellcheck attribute on this
* node.
*/
virtual already_AddRefed<nsIEditor> GetAssociatedEditor();
/**
* Get the frame's offset information for offsetTop/Left/Width/Height.
* @note This method flushes pending notifications (Flush_Layout).
* @param aRect the offset information [OUT]
* @param aOffsetParent the parent the offset is relative to (offsetParent)
* [OUT]
*/
virtual void GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent);
/**
* Returns true if this is the current document's body element
*/
PRBool IsCurrentBodyElement();
/**
* Ensures all editors associated with a subtree are synced, for purposes of
* spellchecking.
*/
static void SyncEditorsOnSubtree(nsIContent* content);
enum ContentEditableTristate {
eInherit = -1,
eFalse = 0,
eTrue = 1
};
/**
* Returns eTrue if the element has a contentEditable attribute and its value
* is "true" or an empty string. Returns eFalse if the element has a
* contentEditable attribute and its value is "false". Otherwise returns
* eInherit.
*/
NS_HIDDEN_(ContentEditableTristate) GetContentEditableValue() const
{
static const nsIContent::AttrValuesArray values[] =
{ &nsGkAtoms::_false, &nsGkAtoms::_true, &nsGkAtoms::_empty, nsnull };
if (!HasFlag(NODE_MAY_HAVE_CONTENT_EDITABLE_ATTR))
return eInherit;
PRInt32 value = FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::contenteditable, values,
eIgnoreCase);
return value > 0 ? eTrue : (value == 0 ? eFalse : eInherit);
}
// Used by A, AREA, LINK, and STYLE.
already_AddRefed<nsIURI> GetHrefURIForAnchors() const;
private:
/**
* Returns whether this element is an editable root. There are two types of
* editable roots:
* 1) the documentElement if the whole document is editable (for example for
* desginMode=on)
* 2) an element that is marked editable with contentEditable=true and that
* doesn't have a parent or whose parent is not editable.
* Note that this doesn't return input and textarea elements that haven't been
* made editable through contentEditable or designMode.
*/
PRBool IsEditableRoot() const;
void ChangeEditableState(PRInt32 aChange);
};
//----------------------------------------------------------------------
/**
* A helper class for form elements that can contain children
*/
class nsGenericHTMLFormElement : public nsGenericHTMLElement,
public nsIFormControl
{
public:
nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo);
virtual ~nsGenericHTMLFormElement();
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
virtual void SaveSubtreeState();
// nsIFormControl
virtual mozilla::dom::Element* GetFormElement();
virtual void SetForm(nsIDOMHTMLFormElement* aForm);
virtual void ClearForm(PRBool aRemoveFromForm, PRBool aNotify);
nsresult GetForm(nsIDOMHTMLFormElement** aForm);
NS_IMETHOD SaveState()
{
return NS_OK;
}
virtual PRBool RestoreState(nsPresState* aState)
{
return PR_FALSE;
}
virtual PRBool AllowDrop()
{
return PR_TRUE;
}
virtual PRBool IsSubmitControl() const;
PRBool IsTextControl(PRBool aExcludePassword) const;
PRBool IsSingleLineTextControl(PRBool aExcludePassword) const;
PRBool IsLabelableControl() const;
// nsIContent
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
PRBool aCompileEventHandlers);
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
PRBool aNullParent = PR_TRUE);
virtual PRUint32 GetDesiredIMEState();
virtual PRInt32 IntrinsicState() const;
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
protected:
virtual nsresult BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify);
virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify);
/**
* Returns if the element should react on autofocus attribute.
*/
virtual PRBool AcceptAutofocus() const
{
return PR_FALSE;
}
/**
* Returns true if the control can be disabled
*/
PRBool CanBeDisabled() const;
void UpdateEditableFormControlState();
PRBool IsSingleLineTextControlInternal(PRBool aExcludePassword, PRInt32 mType) const;
// The focusability state of this form control. eUnfocusable means that it
// shouldn't be focused at all, eInactiveWindow means it's in an inactive
// window, eActiveWindow means it's in an active window.
enum FocusTristate {
eUnfocusable,
eInactiveWindow,
eActiveWindow
};
// Get our focus state. If this returns eInactiveWindow, it will set this
// element as the focused element for that window.
FocusTristate FocusState();
/** The form that contains this control */
nsHTMLFormElement* mForm;
};
// If this flag is set on an nsGenericHTMLFormElement, that means that we have
// added ourselves to our mForm. It's possible to have a non-null mForm, but
// not have this flag set. That happens when the form is set via the content
// sink.
#define ADDED_TO_FORM (1 << ELEMENT_TYPE_SPECIFIC_BITS_OFFSET)
// If this flag is set on an nsGenericHTMLFormElement, that means that its form
// is in the process of being unbound from the tree, and this form element
// hasn't re-found its form in nsGenericHTMLFormElement::UnbindFromTree yet.
#define MAYBE_ORPHAN_FORM_ELEMENT (1 << (ELEMENT_TYPE_SPECIFIC_BITS_OFFSET+1))
// NOTE: I don't think it's possible to have the above two flags set at the
// same time, so if it becomes an issue we can probably merge them into the
// same bit. --bz
// Make sure we have enough space for those bits
PR_STATIC_ASSERT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 1 < 32);
//----------------------------------------------------------------------
/**
* A helper class for frame elements
*/
class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
public nsIDOMNSHTMLFrameElement,
public nsIFrameLoaderOwner
{
public:
nsGenericHTMLFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
PRUint32 aFromParser)
: nsGenericHTMLElement(aNodeInfo)
{
mNetworkCreated = aFromParser == NS_FROM_PARSER_NETWORK;
}
virtual ~nsGenericHTMLFrameElement();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
// nsIDOMNSHTMLFrameElement
NS_DECL_NSIDOMNSHTMLFRAMEELEMENT
// nsIFrameLoaderOwner
NS_DECL_NSIFRAMELOADEROWNER
// nsIContent
virtual PRBool IsHTMLFocusable(PRBool aWithMouse, PRBool *aIsFocusable, PRInt32 *aTabIndex);
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
PRBool aCompileEventHandlers);
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
PRBool aNullParent = PR_TRUE);
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
{
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
}
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify);
virtual void DestroyContent();
nsresult CopyInnerTo(nsGenericElement* aDest) const;
// nsIDOMNSHTMLElement
NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGenericHTMLFrameElement,
nsGenericHTMLElement)
protected:
// This doesn't really ensure a frame loade in all cases, only when
// it makes sense.
nsresult EnsureFrameLoader();
nsresult LoadSrc();
nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
nsRefPtr<nsFrameLoader> mFrameLoader;
// True when the element is created by the parser
// using NS_FROM_PARSER_NETWORK flag.
// If the element is modified, it may lose the flag.
PRPackedBool mNetworkCreated;
};
//----------------------------------------------------------------------
/**
* A macro to implement the NS_NewHTMLXXXElement() functions.
*/
#define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName) \
nsGenericHTMLElement* \
NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo> aNodeInfo, \
PRUint32 aFromParser) \
{ \
return new nsHTML##_elementName##Element(aNodeInfo); \
}
#define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName) \
nsGenericHTMLElement* \
NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo> aNodeInfo, \
PRUint32 aFromParser) \
{ \
return new nsHTML##_elementName##Element(aNodeInfo, aFromParser); \
}
/**
* A macro to implement the getter and setter for a given string
* valued content property. The method uses the generic GetAttr and
* SetAttr methods.
*/
#define NS_IMPL_STRING_ATTR(_class, _method, _atom) \
NS_IMETHODIMP \
_class::Get##_method(nsAString& aValue) \
{ \
return GetAttrHelper(nsGkAtoms::_atom, aValue); \