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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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
« no previous file with comments | « Source/core/svg/graphics/SVGImage.cpp ('k') | Source/core/xml/XPathExpression.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 return ClientRect::create(document->frame()->selection()->absoluteCaretBound s()); 805 return ClientRect::create(document->frame()->selection()->absoluteCaretBound s());
806 } 806 }
807 807
808 PassRefPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionState& es) 808 PassRefPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionState& es)
809 { 809 {
810 if (!element) { 810 if (!element) {
811 es.throwDOMException(InvalidAccessError); 811 es.throwDOMException(InvalidAccessError);
812 return ClientRect::create(); 812 return ClientRect::create();
813 } 813 }
814 814
815 element->document()->updateLayoutIgnorePendingStylesheets(); 815 element->document().updateLayoutIgnorePendingStylesheets();
816 RenderObject* renderer = element->renderer(); 816 RenderObject* renderer = element->renderer();
817 if (!renderer) 817 if (!renderer)
818 return ClientRect::create(); 818 return ClientRect::create();
819 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransform s()); 819 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransform s());
820 } 820 }
821 821
822 PassRefPtr<ClientRectList> Internals::inspectorHighlightRects(Document* document , ExceptionState& es) 822 PassRefPtr<ClientRectList> Internals::inspectorHighlightRects(Document* document , ExceptionState& es)
823 { 823 {
824 if (!document || !document->page()) { 824 if (!document || !document->page()) {
825 es.throwDOMException(InvalidAccessError); 825 es.throwDOMException(InvalidAccessError);
(...skipping 11 matching lines...) Expand all
837 es.throwDOMException(InvalidAccessError); 837 es.throwDOMException(InvalidAccessError);
838 return 0; 838 return 0;
839 } 839 }
840 840
841 DocumentMarker::MarkerTypes markerTypes = 0; 841 DocumentMarker::MarkerTypes markerTypes = 0;
842 if (!markerTypesFrom(markerType, markerTypes)) { 842 if (!markerTypesFrom(markerType, markerTypes)) {
843 es.throwDOMException(SyntaxError); 843 es.throwDOMException(SyntaxError);
844 return 0; 844 return 0;
845 } 845 }
846 846
847 return node->document()->markers()->markersFor(node, markerTypes).size(); 847 return node->document().markers()->markersFor(node, markerTypes).size();
848 } 848 }
849 849
850 unsigned Internals::activeMarkerCountForNode(Node* node, ExceptionState& es) 850 unsigned Internals::activeMarkerCountForNode(Node* node, ExceptionState& es)
851 { 851 {
852 if (!node) { 852 if (!node) {
853 es.throwDOMException(InvalidAccessError); 853 es.throwDOMException(InvalidAccessError);
854 return 0; 854 return 0;
855 } 855 }
856 856
857 // Only TextMatch markers can be active. 857 // Only TextMatch markers can be active.
858 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch; 858 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
859 Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(no de, markerType); 859 Vector<DocumentMarker*> markers = node->document().markers()->markersFor(nod e, markerType);
860 860
861 unsigned activeMarkerCount = 0; 861 unsigned activeMarkerCount = 0;
862 for (Vector<DocumentMarker*>::iterator iter = markers.begin(); iter != marke rs.end(); ++iter) { 862 for (Vector<DocumentMarker*>::iterator iter = markers.begin(); iter != marke rs.end(); ++iter) {
863 if ((*iter)->activeMatch()) 863 if ((*iter)->activeMatch())
864 activeMarkerCount++; 864 activeMarkerCount++;
865 } 865 }
866 866
867 return activeMarkerCount; 867 return activeMarkerCount;
868 } 868 }
869 869
870 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsign ed index, ExceptionState& es) 870 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsign ed index, ExceptionState& es)
871 { 871 {
872 if (!node) { 872 if (!node) {
873 es.throwDOMException(InvalidAccessError); 873 es.throwDOMException(InvalidAccessError);
874 return 0; 874 return 0;
875 } 875 }
876 876
877 DocumentMarker::MarkerTypes markerTypes = 0; 877 DocumentMarker::MarkerTypes markerTypes = 0;
878 if (!markerTypesFrom(markerType, markerTypes)) { 878 if (!markerTypesFrom(markerType, markerTypes)) {
879 es.throwDOMException(SyntaxError); 879 es.throwDOMException(SyntaxError);
880 return 0; 880 return 0;
881 } 881 }
882 882
883 Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(no de, markerTypes); 883 Vector<DocumentMarker*> markers = node->document().markers()->markersFor(nod e, markerTypes);
884 if (markers.size() <= index) 884 if (markers.size() <= index)
885 return 0; 885 return 0;
886 return markers[index]; 886 return markers[index];
887 } 887 }
888 888
889 PassRefPtr<Range> Internals::markerRangeForNode(Node* node, const String& marker Type, unsigned index, ExceptionState& es) 889 PassRefPtr<Range> Internals::markerRangeForNode(Node* node, const String& marker Type, unsigned index, ExceptionState& es)
890 { 890 {
891 DocumentMarker* marker = markerAt(node, markerType, index, es); 891 DocumentMarker* marker = markerAt(node, markerType, index, es);
892 if (!marker) 892 if (!marker)
893 return 0; 893 return 0;
894 return Range::create(node->document(), node, marker->startOffset(), node, ma rker->endOffset()); 894 return Range::create(&node->document(), node, marker->startOffset(), node, m arker->endOffset());
895 } 895 }
896 896
897 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionState& es) 897 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionState& es)
898 { 898 {
899 DocumentMarker* marker = markerAt(node, markerType, index, es); 899 DocumentMarker* marker = markerAt(node, markerType, index, es);
900 if (!marker) 900 if (!marker)
901 return String(); 901 return String();
902 return marker->description(); 902 return marker->description();
903 } 903 }
904 904
905 void Internals::addTextMatchMarker(const Range* range, bool isActive) 905 void Internals::addTextMatchMarker(const Range* range, bool isActive)
906 { 906 {
907 range->ownerDocument()->updateLayoutIgnorePendingStylesheets(); 907 range->ownerDocument()->updateLayoutIgnorePendingStylesheets();
908 range->ownerDocument()->markers()->addTextMatchMarker(range, isActive); 908 range->ownerDocument()->markers()->addTextMatchMarker(range, isActive);
909 } 909 }
910 910
911 void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endO ffset, bool active, ExceptionState& es) 911 void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endO ffset, bool active, ExceptionState& es)
912 { 912 {
913 if (!node) { 913 if (!node) {
914 es.throwDOMException(InvalidAccessError); 914 es.throwDOMException(InvalidAccessError);
915 return; 915 return;
916 } 916 }
917 917
918 node->document()->markers()->setMarkersActive(node, startOffset, endOffset, active); 918 node->document().markers()->setMarkersActive(node, startOffset, endOffset, a ctive);
919 } 919 }
920 920
921 void Internals::setScrollViewPosition(Document* document, long x, long y, Except ionState& es) 921 void Internals::setScrollViewPosition(Document* document, long x, long y, Except ionState& es)
922 { 922 {
923 if (!document || !document->view()) { 923 if (!document || !document->view()) {
924 es.throwDOMException(InvalidAccessError); 924 es.throwDOMException(InvalidAccessError);
925 return; 925 return;
926 } 926 }
927 927
928 FrameView* frameView = document->view(); 928 FrameView* frameView = document->view();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 { 1083 {
1084 if (!element->hasTagName(inputTag)) { 1084 if (!element->hasTagName(inputTag)) {
1085 es.throwDOMException(InvalidAccessError); 1085 es.throwDOMException(InvalidAccessError);
1086 return; 1086 return;
1087 } 1087 }
1088 toHTMLInputElement(element)->setAutofilled(enabled); 1088 toHTMLInputElement(element)->setAutofilled(enabled);
1089 } 1089 }
1090 1090
1091 void Internals::scrollElementToRect(Element* element, long x, long y, long w, lo ng h, ExceptionState& es) 1091 void Internals::scrollElementToRect(Element* element, long x, long y, long w, lo ng h, ExceptionState& es)
1092 { 1092 {
1093 if (!element || !element->document() || !element->document()->view()) { 1093 if (!element || !element->document().view()) {
1094 es.throwDOMException(InvalidAccessError); 1094 es.throwDOMException(InvalidAccessError);
1095 return; 1095 return;
1096 } 1096 }
1097 FrameView* frameView = element->document()->view(); 1097 FrameView* frameView = element->document().view();
1098 frameView->scrollElementToRect(element, IntRect(x, y, w, h)); 1098 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
1099 } 1099 }
1100 1100
1101 void Internals::paintControlTints(Document* document, ExceptionState& es) 1101 void Internals::paintControlTints(Document* document, ExceptionState& es)
1102 { 1102 {
1103 if (!document || !document->view()) { 1103 if (!document || !document->view()) {
1104 es.throwDOMException(InvalidAccessError); 1104 es.throwDOMException(InvalidAccessError);
1105 return; 1105 return;
1106 } 1106 }
1107 1107
1108 FrameView* frameView = document->view(); 1108 FrameView* frameView = document->view();
1109 frameView->paintControlTints(); 1109 frameView->paintControlTints();
1110 } 1110 }
1111 1111
1112 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rang eLocation, int rangeLength, ExceptionState& es) 1112 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rang eLocation, int rangeLength, ExceptionState& es)
1113 { 1113 {
1114 if (!scope) { 1114 if (!scope) {
1115 es.throwDOMException(InvalidAccessError); 1115 es.throwDOMException(InvalidAccessError);
1116 return 0; 1116 return 0;
1117 } 1117 }
1118 1118
1119 // TextIterator depends on Layout information, make sure layout it up to dat e. 1119 // TextIterator depends on Layout information, make sure layout it up to dat e.
1120 scope->document()->updateLayoutIgnorePendingStylesheets(); 1120 scope->document().updateLayoutIgnorePendingStylesheets();
1121 1121
1122 return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeL ength); 1122 return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeL ength);
1123 } 1123 }
1124 1124
1125 unsigned Internals::locationFromRange(Element* scope, const Range* range, Except ionState& es) 1125 unsigned Internals::locationFromRange(Element* scope, const Range* range, Except ionState& es)
1126 { 1126 {
1127 if (!scope || !range) { 1127 if (!scope || !range) {
1128 es.throwDOMException(InvalidAccessError); 1128 es.throwDOMException(InvalidAccessError);
1129 return 0; 1129 return 0;
1130 } 1130 }
1131 1131
1132 // TextIterator depends on Layout information, make sure layout it up to dat e. 1132 // TextIterator depends on Layout information, make sure layout it up to dat e.
1133 scope->document()->updateLayoutIgnorePendingStylesheets(); 1133 scope->document().updateLayoutIgnorePendingStylesheets();
1134 1134
1135 size_t location = 0; 1135 size_t location = 0;
1136 size_t unusedLength = 0; 1136 size_t unusedLength = 0;
1137 TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLe ngth); 1137 TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLe ngth);
1138 return location; 1138 return location;
1139 } 1139 }
1140 1140
1141 unsigned Internals::lengthFromRange(Element* scope, const Range* range, Exceptio nState& es) 1141 unsigned Internals::lengthFromRange(Element* scope, const Range* range, Exceptio nState& es)
1142 { 1142 {
1143 if (!scope || !range) { 1143 if (!scope || !range) {
1144 es.throwDOMException(InvalidAccessError); 1144 es.throwDOMException(InvalidAccessError);
1145 return 0; 1145 return 0;
1146 } 1146 }
1147 1147
1148 // TextIterator depends on Layout information, make sure layout it up to dat e. 1148 // TextIterator depends on Layout information, make sure layout it up to dat e.
1149 scope->document()->updateLayoutIgnorePendingStylesheets(); 1149 scope->document().updateLayoutIgnorePendingStylesheets();
1150 1150
1151 size_t unusedLocation = 0; 1151 size_t unusedLocation = 0;
1152 size_t length = 0; 1152 size_t length = 0;
1153 TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, le ngth); 1153 TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, le ngth);
1154 return length; 1154 return length;
1155 } 1155 }
1156 1156
1157 String Internals::rangeAsText(const Range* range, ExceptionState& es) 1157 String Internals::rangeAsText(const Range* range, ExceptionState& es)
1158 { 1158 {
1159 if (!range) { 1159 if (!range) {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 return elementLayerTreeAsText(element, 0, es); 1669 return elementLayerTreeAsText(element, 0, es);
1670 } 1670 }
1671 1671
1672 static PassRefPtr<NodeList> paintOrderList(Element* element, ExceptionState& es, RenderLayer::PaintOrderListType type) 1672 static PassRefPtr<NodeList> paintOrderList(Element* element, ExceptionState& es, RenderLayer::PaintOrderListType type)
1673 { 1673 {
1674 if (!element) { 1674 if (!element) {
1675 es.throwDOMException(InvalidAccessError); 1675 es.throwDOMException(InvalidAccessError);
1676 return 0; 1676 return 0;
1677 } 1677 }
1678 1678
1679 element->document()->updateLayout(); 1679 element->document().updateLayout();
1680 1680
1681 RenderObject* renderer = element->renderer(); 1681 RenderObject* renderer = element->renderer();
1682 if (!renderer || !renderer->isBox()) { 1682 if (!renderer || !renderer->isBox()) {
1683 es.throwDOMException(InvalidAccessError); 1683 es.throwDOMException(InvalidAccessError);
1684 return 0; 1684 return 0;
1685 } 1685 }
1686 1686
1687 RenderLayer* layer = toRenderBox(renderer)->layer(); 1687 RenderLayer* layer = toRenderBox(renderer)->layer();
1688 if (!layer) { 1688 if (!layer) {
1689 es.throwDOMException(InvalidAccessError); 1689 es.throwDOMException(InvalidAccessError);
(...skipping 15 matching lines...) Expand all
1705 return paintOrderList(element, es, RenderLayer::AfterPromote); 1705 return paintOrderList(element, es, RenderLayer::AfterPromote);
1706 } 1706 }
1707 1707
1708 bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, Excep tionState& es) 1708 bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, Excep tionState& es)
1709 { 1709 {
1710 if (!element1 || !element2) { 1710 if (!element1 || !element2) {
1711 es.throwDOMException(InvalidAccessError); 1711 es.throwDOMException(InvalidAccessError);
1712 return 0; 1712 return 0;
1713 } 1713 }
1714 1714
1715 element1->document()->updateLayout(); 1715 element1->document().updateLayout();
1716 1716
1717 RenderObject* renderer1 = element1->renderer(); 1717 RenderObject* renderer1 = element1->renderer();
1718 RenderObject* renderer2 = element2->renderer(); 1718 RenderObject* renderer2 = element2->renderer();
1719 if (!renderer1 || !renderer2 || !renderer1->isBox() || !renderer2->isBox()) { 1719 if (!renderer1 || !renderer2 || !renderer1->isBox() || !renderer2->isBox()) {
1720 es.throwDOMException(InvalidAccessError); 1720 es.throwDOMException(InvalidAccessError);
1721 return 0; 1721 return 0;
1722 } 1722 }
1723 1723
1724 RenderLayer* layer1 = toRenderBox(renderer1)->layer(); 1724 RenderLayer* layer1 = toRenderBox(renderer1)->layer();
1725 RenderLayer* layer2 = toRenderBox(renderer2)->layer(); 1725 RenderLayer* layer2 = toRenderBox(renderer2)->layer();
(...skipping 15 matching lines...) Expand all
1741 return document->frame()->layerTreeAsText(flags); 1741 return document->frame()->layerTreeAsText(flags);
1742 } 1742 }
1743 1743
1744 String Internals::elementLayerTreeAsText(Element* element, unsigned flags, Excep tionState& es) const 1744 String Internals::elementLayerTreeAsText(Element* element, unsigned flags, Excep tionState& es) const
1745 { 1745 {
1746 if (!element) { 1746 if (!element) {
1747 es.throwDOMException(InvalidAccessError); 1747 es.throwDOMException(InvalidAccessError);
1748 return String(); 1748 return String();
1749 } 1749 }
1750 1750
1751 element->document()->updateLayout(); 1751 element->document().updateLayout();
1752 1752
1753 RenderObject* renderer = element->renderer(); 1753 RenderObject* renderer = element->renderer();
1754 if (!renderer || !renderer->isBox()) { 1754 if (!renderer || !renderer->isBox()) {
1755 es.throwDOMException(InvalidAccessError); 1755 es.throwDOMException(InvalidAccessError);
1756 return String(); 1756 return String();
1757 } 1757 }
1758 1758
1759 RenderLayer* layer = toRenderBox(renderer)->layer(); 1759 RenderLayer* layer = toRenderBox(renderer)->layer();
1760 if (!layer 1760 if (!layer
1761 || !layer->backing() 1761 || !layer->backing()
1762 || !layer->backing()->graphicsLayer()) { 1762 || !layer->backing()->graphicsLayer()) {
1763 // Don't raise exception in these cases which may be normally used in te sts. 1763 // Don't raise exception in these cases which may be normally used in te sts.
1764 return String(); 1764 return String();
1765 } 1765 }
1766 1766
1767 return layer->backing()->graphicsLayer()->layerTreeAsText(flags); 1767 return layer->backing()->graphicsLayer()->layerTreeAsText(flags);
1768 } 1768 }
1769 1769
1770 void Internals::setNeedsCompositedScrolling(Element* element, unsigned needsComp ositedScrolling, ExceptionState& es) 1770 void Internals::setNeedsCompositedScrolling(Element* element, unsigned needsComp ositedScrolling, ExceptionState& es)
1771 { 1771 {
1772 if (!element) { 1772 if (!element) {
1773 es.throwDOMException(InvalidAccessError); 1773 es.throwDOMException(InvalidAccessError);
1774 return; 1774 return;
1775 } 1775 }
1776 1776
1777 element->document()->updateLayout(); 1777 element->document().updateLayout();
1778 1778
1779 RenderObject* renderer = element->renderer(); 1779 RenderObject* renderer = element->renderer();
1780 if (!renderer || !renderer->isBox()) { 1780 if (!renderer || !renderer->isBox()) {
1781 es.throwDOMException(InvalidAccessError); 1781 es.throwDOMException(InvalidAccessError);
1782 return; 1782 return;
1783 } 1783 }
1784 1784
1785 RenderLayer* layer = toRenderBox(renderer)->layer(); 1785 RenderLayer* layer = toRenderBox(renderer)->layer();
1786 if (!layer) { 1786 if (!layer) {
1787 es.throwDOMException(InvalidAccessError); 1787 es.throwDOMException(InvalidAccessError);
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2205 return false; 2205 return false;
2206 sharedContext->getExtensions()->loseContextCHROMIUM(Extensions3D::GUILTY_CON TEXT_RESET_ARB, Extensions3D::INNOCENT_CONTEXT_RESET_ARB); 2206 sharedContext->getExtensions()->loseContextCHROMIUM(Extensions3D::GUILTY_CON TEXT_RESET_ARB, Extensions3D::INNOCENT_CONTEXT_RESET_ARB);
2207 // To prevent tests that call loseSharedGraphicsContext3D from being 2207 // To prevent tests that call loseSharedGraphicsContext3D from being
2208 // flaky, we call finish so that the context is guaranteed to be lost 2208 // flaky, we call finish so that the context is guaranteed to be lost
2209 // synchronously (i.e. before returning). 2209 // synchronously (i.e. before returning).
2210 sharedContext->finish(); 2210 sharedContext->finish();
2211 return true; 2211 return true;
2212 } 2212 }
2213 2213
2214 } 2214 }
OLDNEW
« no previous file with comments | « Source/core/svg/graphics/SVGImage.cpp ('k') | Source/core/xml/XPathExpression.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698