Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Side by Side Diff: Source/core/testing/Internals.cpp

Issue 193623002: Use new is*Element() helper functions more in core/ code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 10 matching lines...) Expand all
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "Internals.h" 28 #include "Internals.h"
29 29
30 #include <v8.h> 30 #include <v8.h>
31 #include "HTMLNames.h"
32 #include "InspectorFrontendClientLocal.h" 31 #include "InspectorFrontendClientLocal.h"
33 #include "InternalProfilers.h" 32 #include "InternalProfilers.h"
34 #include "InternalRuntimeFlags.h" 33 #include "InternalRuntimeFlags.h"
35 #include "InternalSettings.h" 34 #include "InternalSettings.h"
36 #include "LayerRect.h" 35 #include "LayerRect.h"
37 #include "LayerRectList.h" 36 #include "LayerRectList.h"
38 #include "MallocStatistics.h" 37 #include "MallocStatistics.h"
39 #include "MockPagePopupDriver.h" 38 #include "MockPagePopupDriver.h"
40 #include "RuntimeEnabledFeatures.h" 39 #include "RuntimeEnabledFeatures.h"
41 #include "TypeConversions.h" 40 #include "TypeConversions.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return element1->renderStyle() == element2->renderStyle(); 370 return element1->renderStyle() == element2->renderStyle();
372 } 371 }
373 372
374 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionState& ex ceptionState) 373 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionState& ex ceptionState)
375 { 374 {
376 if (!insertionPoint || !insertionPoint->isInsertionPoint()) { 375 if (!insertionPoint || !insertionPoint->isInsertionPoint()) {
377 exceptionState.throwDOMException(InvalidAccessError, "The insertion poin t provided is invalid."); 376 exceptionState.throwDOMException(InvalidAccessError, "The insertion poin t provided is invalid.");
378 return false; 377 return false;
379 } 378 }
380 379
381 return insertionPoint->hasTagName(contentTag) && toHTMLContentElement(insert ionPoint)->isSelectValid(); 380 return isHTMLContentElement(*insertionPoint) && toHTMLContentElement(*insert ionPoint).isSelectValid();
382 } 381 }
383 382
384 Node* Internals::treeScopeRootNode(Node* node, ExceptionState& exceptionState) 383 Node* Internals::treeScopeRootNode(Node* node, ExceptionState& exceptionState)
385 { 384 {
386 if (!node) { 385 if (!node) {
387 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Node")); 386 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Node"));
388 return 0; 387 return 0;
389 } 388 }
390 389
391 return &node->treeScope().rootNode(); 390 return &node->treeScope().rootNode();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 if (element && isHTMLTextFormControlElement(*element)) { 695 if (element && isHTMLTextFormControlElement(*element)) {
697 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible()) 696 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
698 return toHTMLTextFormControlElement(element)->placeholderElement()-> textContent(); 697 return toHTMLTextFormControlElement(element)->placeholderElement()-> textContent();
699 } 698 }
700 699
701 return String(); 700 return String();
702 } 701 }
703 702
704 void Internals::selectColorInColorChooser(Element* element, const String& colorV alue) 703 void Internals::selectColorInColorChooser(Element* element, const String& colorV alue)
705 { 704 {
706 if (!element->hasTagName(inputTag)) 705 ASSERT(element);
706 if (!isHTMLInputElement(*element))
707 return; 707 return;
708 Color color; 708 Color color;
709 if (!color.setFromString(colorValue)) 709 if (!color.setFromString(colorValue))
710 return; 710 return;
711 toHTMLInputElement(element)->selectColorInColorChooser(color); 711 toHTMLInputElement(*element).selectColorInColorChooser(color);
712 } 712 }
713 713
714 bool Internals::hasAutofocusRequest(Document* document) 714 bool Internals::hasAutofocusRequest(Document* document)
715 { 715 {
716 if (!document) 716 if (!document)
717 document = contextDocument(); 717 document = contextDocument();
718 return document->autofocusElement(); 718 return document->autofocusElement();
719 } 719 }
720 720
721 bool Internals::hasAutofocusRequest() 721 bool Internals::hasAutofocusRequest()
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 return builder.toString(); 964 return builder.toString();
965 } 965 }
966 966
967 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionState& except ionState) 967 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionState& except ionState)
968 { 968 {
969 if (!textField) { 969 if (!textField) {
970 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element")); 970 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element"));
971 return false; 971 return false;
972 } 972 }
973 973
974 if (textField->hasTagName(inputTag)) 974 if (isHTMLInputElement(*textField))
975 return toHTMLInputElement(textField)->lastChangeWasUserEdit(); 975 return toHTMLInputElement(*textField).lastChangeWasUserEdit();
976 976
977 if (textField->hasTagName(textareaTag)) 977 if (isHTMLTextAreaElement(*textField))
978 return toHTMLTextAreaElement(textField)->lastChangeWasUserEdit(); 978 return toHTMLTextAreaElement(*textField).lastChangeWasUserEdit();
979 979
980 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a TEXTAREA."); 980 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a TEXTAREA.");
981 return false; 981 return false;
982 } 982 }
983 983
984 bool Internals::elementShouldAutoComplete(Element* element, ExceptionState& exce ptionState) 984 bool Internals::elementShouldAutoComplete(Element* element, ExceptionState& exce ptionState)
985 { 985 {
986 if (!element) { 986 if (!element) {
987 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element")); 987 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element"));
988 return false; 988 return false;
989 } 989 }
990 990
991 if (element->hasTagName(inputTag)) 991 if (isHTMLInputElement(*element))
992 return toHTMLInputElement(element)->shouldAutocomplete(); 992 return toHTMLInputElement(*element).shouldAutocomplete();
993 993
994 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT."); 994 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
995 return false; 995 return false;
996 } 996 }
997 997
998 String Internals::suggestedValue(Element* element, ExceptionState& exceptionStat e) 998 String Internals::suggestedValue(Element* element, ExceptionState& exceptionStat e)
999 { 999 {
1000 if (!element) { 1000 if (!element) {
1001 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element")); 1001 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element"));
1002 return String(); 1002 return String();
1003 } 1003 }
1004 1004
1005 if (!element->isFormControlElement()) { 1005 if (!element->isFormControlElement()) {
1006 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not a form control element."); 1006 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not a form control element.");
1007 return String(); 1007 return String();
1008 } 1008 }
1009 1009
1010 String suggestedValue; 1010 String suggestedValue;
1011 if (element->hasTagName(inputTag)) 1011 if (isHTMLInputElement(*element))
1012 suggestedValue = toHTMLInputElement(element)->suggestedValue(); 1012 suggestedValue = toHTMLInputElement(*element).suggestedValue();
1013 1013
1014 if (element->hasTagName(textareaTag)) 1014 if (isHTMLTextAreaElement(*element))
1015 suggestedValue = toHTMLTextAreaElement(element)->suggestedValue(); 1015 suggestedValue = toHTMLTextAreaElement(*element).suggestedValue();
1016 return suggestedValue; 1016 return suggestedValue;
1017 } 1017 }
1018 1018
1019 void Internals::setSuggestedValue(Element* element, const String& value, Excepti onState& exceptionState) 1019 void Internals::setSuggestedValue(Element* element, const String& value, Excepti onState& exceptionState)
1020 { 1020 {
1021 if (!element) { 1021 if (!element) {
1022 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element")); 1022 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element"));
1023 return; 1023 return;
1024 } 1024 }
1025 1025
1026 if (!element->isFormControlElement()) { 1026 if (!element->isFormControlElement()) {
1027 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not a form control element."); 1027 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not a form control element.");
1028 return; 1028 return;
1029 } 1029 }
1030 1030
1031 if (element->hasTagName(inputTag)) 1031 if (isHTMLInputElement(*element))
1032 toHTMLInputElement(element)->setSuggestedValue(value); 1032 toHTMLInputElement(*element).setSuggestedValue(value);
1033 1033
1034 if (element->hasTagName(textareaTag)) 1034 if (isHTMLTextAreaElement(*element))
1035 toHTMLTextAreaElement(element)->setSuggestedValue(value); 1035 toHTMLTextAreaElement(*element).setSuggestedValue(value);
1036 } 1036 }
1037 1037
1038 void Internals::setEditingValue(Element* element, const String& value, Exception State& exceptionState) 1038 void Internals::setEditingValue(Element* element, const String& value, Exception State& exceptionState)
1039 { 1039 {
1040 if (!element) { 1040 if (!element) {
1041 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element")); 1041 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element"));
1042 return; 1042 return;
1043 } 1043 }
1044 1044
1045 if (!element->hasTagName(inputTag)) { 1045 if (!isHTMLInputElement(*element)) {
1046 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not an INPUT."); 1046 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not an INPUT.");
1047 return; 1047 return;
1048 } 1048 }
1049 1049
1050 toHTMLInputElement(element)->setEditingValue(value); 1050 toHTMLInputElement(*element).setEditingValue(value);
1051 } 1051 }
1052 1052
1053 void Internals::setAutofilled(Element* element, bool enabled, ExceptionState& ex ceptionState) 1053 void Internals::setAutofilled(Element* element, bool enabled, ExceptionState& ex ceptionState)
1054 { 1054 {
1055 if (!element->isFormControlElement()) { 1055 if (!element->isFormControlElement()) {
1056 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not a form control element."); 1056 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not a form control element.");
1057 return; 1057 return;
1058 } 1058 }
1059 toHTMLFormControlElement(element)->setAutofilled(enabled); 1059 toHTMLFormControlElement(element)->setAutofilled(enabled);
1060 } 1060 }
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(0, exceptionState) ; 2095 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(0, exceptionState) ;
2096 } 2096 }
2097 2097
2098 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionState& exceptionState) 2098 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionState& exceptionState)
2099 { 2099 {
2100 Document* document; 2100 Document* document;
2101 if (!node) { 2101 if (!node) {
2102 document = contextDocument(); 2102 document = contextDocument();
2103 } else if (node->isDocumentNode()) { 2103 } else if (node->isDocumentNode()) {
2104 document = toDocument(node); 2104 document = toDocument(node);
2105 } else if (node->hasTagName(HTMLNames::iframeTag)) { 2105 } else if (isHTMLIFrameElement(*node)) {
2106 document = toHTMLIFrameElement(node)->contentDocument(); 2106 document = toHTMLIFrameElement(*node).contentDocument();
2107 } else { 2107 } else {
2108 exceptionState.throwTypeError("The node provided is neither a document n or an IFrame."); 2108 exceptionState.throwTypeError("The node provided is neither a document n or an IFrame.");
2109 return; 2109 return;
2110 } 2110 }
2111 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksS ynchronously); 2111 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksS ynchronously);
2112 } 2112 }
2113 2113
2114 PassRefPtr<ClientRectList> Internals::draggableRegions(Document* document, Excep tionState& exceptionState) 2114 PassRefPtr<ClientRectList> Internals::draggableRegions(Document* document, Excep tionState& exceptionState)
2115 { 2115 {
2116 return annotatedRegions(document, true, exceptionState); 2116 return annotatedRegions(document, true, exceptionState);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 if (!document) { 2278 if (!document) {
2279 exceptionState.throwDOMException(InvalidAccessError, "No context documen t is available."); 2279 exceptionState.throwDOMException(InvalidAccessError, "No context documen t is available.");
2280 return String(); 2280 return String();
2281 } 2281 }
2282 2282
2283 return document->baseURL().string(); 2283 return document->baseURL().string();
2284 } 2284 }
2285 2285
2286 bool Internals::isSelectPopupVisible(Node* node) 2286 bool Internals::isSelectPopupVisible(Node* node)
2287 { 2287 {
2288 if (!node->hasTagName(HTMLNames::selectTag)) 2288 ASSERT(node);
2289 if (!isHTMLSelectElement(*node))
2289 return false; 2290 return false;
2290 2291
2291 HTMLSelectElement* select = toHTMLSelectElement(node); 2292 HTMLSelectElement& select = toHTMLSelectElement(*node);
2292 2293
2293 RenderObject* renderer = select->renderer(); 2294 RenderObject* renderer = select.renderer();
2294 if (!renderer->isMenuList()) 2295 if (!renderer->isMenuList())
2295 return false; 2296 return false;
2296 2297
2297 RenderMenuList* menuList = toRenderMenuList(renderer); 2298 RenderMenuList* menuList = toRenderMenuList(renderer);
2298 return menuList->popupIsVisible(); 2299 return menuList->popupIsVisible();
2299 } 2300 }
2300 2301
2301 bool Internals::loseSharedGraphicsContext3D() 2302 bool Internals::loseSharedGraphicsContext3D()
2302 { 2303 {
2303 OwnPtr<blink::WebGraphicsContext3DProvider> sharedProvider = adoptPtr(blink: :Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); 2304 OwnPtr<blink::WebGraphicsContext3DProvider> sharedProvider = adoptPtr(blink: :Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 return document->page()->chrome().client().isCompositorFramePending(); 2337 return document->page()->chrome().client().isCompositorFramePending();
2337 } 2338 }
2338 2339
2339 void Internals::setZoomFactor(float factor) 2340 void Internals::setZoomFactor(float factor)
2340 { 2341 {
2341 frame()->setPageZoomFactor(factor); 2342 frame()->setPageZoomFactor(factor);
2342 } 2343 }
2343 2344
2344 void Internals::setShouldRevealPassword(Element* element, bool reveal, Exception State& exceptionState) 2345 void Internals::setShouldRevealPassword(Element* element, bool reveal, Exception State& exceptionState)
2345 { 2346 {
2346 if (!element || !element->hasTagName(inputTag)) { 2347 if (!isHTMLInputElement(element)) {
2347 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element")); 2348 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: argumentNullOrIncorrectType(1, "Element"));
2348 return; 2349 return;
2349 } 2350 }
2350 2351
2351 return toHTMLInputElement(element)->setShouldRevealPassword(reveal); 2352 return toHTMLInputElement(*element).setShouldRevealPassword(reveal);
2352 } 2353 }
2353 2354
2354 namespace { 2355 namespace {
2355 2356
2356 class AddOneFunction : public ScriptFunction { 2357 class AddOneFunction : public ScriptFunction {
2357 public: 2358 public:
2358 static PassOwnPtr<ScriptFunction> create(ExecutionContext* context) 2359 static PassOwnPtr<ScriptFunction> create(ExecutionContext* context)
2359 { 2360 {
2360 return adoptPtr(new AddOneFunction(toIsolate(context))); 2361 return adoptPtr(new AddOneFunction(toIsolate(context)));
2361 } 2362 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 } 2410 }
2410 2411
2411 String Internals::textSurroundingNode(Node* node, int x, int y, unsigned long ma xLength) 2412 String Internals::textSurroundingNode(Node* node, int x, int y, unsigned long ma xLength)
2412 { 2413 {
2413 blink::WebPoint point(x, y); 2414 blink::WebPoint point(x, y);
2414 SurroundingText surroundingText(VisiblePosition(node->renderer()->positionFo rPoint(static_cast<IntPoint>(point))), maxLength); 2415 SurroundingText surroundingText(VisiblePosition(node->renderer()->positionFo rPoint(static_cast<IntPoint>(point))), maxLength);
2415 return surroundingText.content(); 2416 return surroundingText.content();
2416 } 2417 }
2417 2418
2418 } 2419 }
OLDNEW
« no previous file with comments | « Source/core/plugins/PluginOcclusionSupport.cpp ('k') | Source/core/xml/parser/XMLDocumentParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698