Changeset 95860 in webkit
- Timestamp:
- Sep 23, 2011 2:39:52 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r95859 r95860 1 2011-09-23 Fady Samuel <fsamuel@chromium.org> 2 3 Refactor paintOverhangAreas to allow non-Mac Chromium platforms to reuse code 4 https://bugs.webkit.org/show_bug.cgi?id=68648 5 6 Reviewed by Dimitri Glazkov. 7 8 No new tests because there's no change in functionality (yet). 9 10 * platform/chromium/ScrollbarThemeChromium.cpp: 11 (WebCore::ScrollbarThemeChromium::ScrollbarThemeChromium): 12 (WebCore::ScrollbarThemeChromium::~ScrollbarThemeChromium): 13 (WebCore::ScrollbarThemeChromium::paintOverhangAreas): 14 * platform/chromium/ScrollbarThemeChromium.h: 15 * platform/chromium/ScrollbarThemeChromiumMac.h: 16 * platform/chromium/ScrollbarThemeChromiumMac.mm: 17 (WebCore::ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac): 18 1 19 2011-09-23 Ojan Vafai <ojan@chromium.org> 2 20 -
trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.cpp
r94275 r95860 29 29 30 30 #include "PlatformMouseEvent.h" 31 32 #if ENABLE(RUBBER_BANDING) 33 #include "ScrollView.h" 34 #endif 35 31 36 #include "ScrollableArea.h" 32 37 #include "Scrollbar.h" … … 39 44 40 45 namespace WebCore { 46 47 #if ENABLE(RUBBER_BANDING) 48 ScrollbarThemeChromium::ScrollbarThemeChromium() 49 { 50 static bool initialized = false; 51 if (!initialized) { 52 initialized = true; 53 // Load the linen pattern image used for overhang drawing. 54 RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern"); 55 m_overhangPattern = Pattern::create(patternImage, true, true); 56 } 57 } 58 59 ScrollbarThemeChromium::~ScrollbarThemeChromium() 60 { 61 } 62 63 void ScrollbarThemeChromium::paintOverhangAreas(ScrollView* view, GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect) 64 { 65 // The extent of each shadow in pixels. 66 const int kShadowSize = 4; 67 // Offset of negative one pixel to make the gradient blend with the toolbar's bottom border. 68 const int kToolbarShadowOffset = -1; 69 const struct { 70 float stop; 71 Color color; 72 } kShadowColors[] = { 73 { 0.000, Color(0, 0, 0, 255) }, 74 { 0.125, Color(0, 0, 0, 57) }, 75 { 0.375, Color(0, 0, 0, 41) }, 76 { 0.625, Color(0, 0, 0, 18) }, 77 { 0.875, Color(0, 0, 0, 6) }, 78 { 1.000, Color(0, 0, 0, 0) } 79 }; 80 const unsigned kNumShadowColors = sizeof(kShadowColors) / sizeof(kShadowColors[0]); 81 82 const bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty(); 83 const bool hasVerticalOverhang = !verticalOverhangRect.isEmpty(); 84 // Prefer non-additive shadows, but degrade to additive shadows if there is vertical overhang. 85 const bool useAdditiveShadows = hasVerticalOverhang; 86 87 GraphicsContextStateSaver stateSaver(*context); 88 89 context->setFillPattern(m_overhangPattern); 90 if (hasHorizontalOverhang) 91 context->fillRect(intersection(horizontalOverhangRect, dirtyRect)); 92 if (hasVerticalOverhang) 93 context->fillRect(intersection(verticalOverhangRect, dirtyRect)); 94 95 IntSize scrollOffset = view->scrollOffset(); 96 FloatPoint shadowCornerOrigin; 97 FloatPoint shadowCornerOffset; 98 99 // Draw the shadow for the horizontal overhang. 100 if (hasHorizontalOverhang) { 101 int toolbarShadowHeight = kShadowSize; 102 RefPtr<Gradient> gradient; 103 IntRect shadowRect = horizontalOverhangRect; 104 shadowRect.setHeight(kShadowSize); 105 if (scrollOffset.height() < 0) { 106 if (useAdditiveShadows) { 107 toolbarShadowHeight = std::min(horizontalOverhangRect.height(), kShadowSize); 108 } else if (horizontalOverhangRect.height() < 2 * kShadowSize + kToolbarShadowOffset) { 109 // Split the overhang area between the web content shadow and toolbar shadow if it's too small. 110 shadowRect.setHeight((horizontalOverhangRect.height() + 1) / 2); 111 toolbarShadowHeight = horizontalOverhangRect.height() - shadowRect.height() - kToolbarShadowOffset; 112 } 113 shadowRect.setY(horizontalOverhangRect.maxY() - shadowRect.height()); 114 gradient = Gradient::create(FloatPoint(0, shadowRect.maxY()), FloatPoint(0, shadowRect.maxY() - kShadowSize)); 115 shadowCornerOrigin.setY(shadowRect.maxY()); 116 shadowCornerOffset.setY(-kShadowSize); 117 } else { 118 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY())); 119 shadowCornerOrigin.setY(shadowRect.y()); 120 } 121 if (hasVerticalOverhang) { 122 shadowRect.setWidth(shadowRect.width() - verticalOverhangRect.width()); 123 if (scrollOffset.width() < 0) { 124 shadowRect.setX(shadowRect.x() + verticalOverhangRect.width()); 125 shadowCornerOrigin.setX(shadowRect.x()); 126 shadowCornerOffset.setX(-kShadowSize); 127 } else 128 shadowCornerOrigin.setX(shadowRect.maxX()); 129 } 130 for (unsigned i = 0; i < kNumShadowColors; i++) 131 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 132 context->setFillGradient(gradient); 133 context->fillRect(intersection(shadowRect, dirtyRect)); 134 135 // Draw a drop-shadow from the toolbar. 136 if (scrollOffset.height() < 0) { 137 shadowRect.setY(kToolbarShadowOffset); 138 shadowRect.setHeight(toolbarShadowHeight); 139 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.y() + kShadowSize)); 140 for (unsigned i = 0; i < kNumShadowColors; i++) 141 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 142 context->setFillGradient(gradient); 143 context->fillRect(intersection(shadowRect, dirtyRect)); 144 } 145 } 146 147 // Draw the shadow for the vertical overhang. 148 if (hasVerticalOverhang) { 149 RefPtr<Gradient> gradient; 150 IntRect shadowRect = verticalOverhangRect; 151 shadowRect.setWidth(kShadowSize); 152 if (scrollOffset.width() < 0) { 153 shadowRect.setX(verticalOverhangRect.maxX() - shadowRect.width()); 154 gradient = Gradient::create(FloatPoint(shadowRect.maxX(), 0), FloatPoint(shadowRect.x(), 0)); 155 } else 156 gradient = Gradient::create(FloatPoint(shadowRect.x(), 0), FloatPoint(shadowRect.maxX(), 0)); 157 158 for (unsigned i = 0; i < kNumShadowColors; i++) 159 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 160 context->setFillGradient(gradient); 161 context->fillRect(intersection(shadowRect, dirtyRect)); 162 163 // Draw a drop-shadow from the toolbar. 164 shadowRect = verticalOverhangRect; 165 shadowRect.setY(kToolbarShadowOffset); 166 shadowRect.setHeight(kShadowSize); 167 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY())); 168 for (unsigned i = 0; i < kNumShadowColors; i++) 169 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 170 context->setFillGradient(gradient); 171 context->fillRect(intersection(shadowRect, dirtyRect)); 172 } 173 174 // If both rectangles present, draw a radial gradient for the corner. 175 if (hasHorizontalOverhang && hasVerticalOverhang) { 176 RefPtr<Gradient> gradient = Gradient::create(shadowCornerOrigin, 0, shadowCornerOrigin, kShadowSize); 177 for (unsigned i = 0; i < kNumShadowColors; i++) 178 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 179 context->setFillGradient(gradient); 180 context->fillRect(FloatRect(shadowCornerOrigin.x() + shadowCornerOffset.x(), shadowCornerOrigin.y() + shadowCornerOffset.y(), kShadowSize, kShadowSize)); 181 } 182 } 183 #endif 41 184 42 185 bool ScrollbarThemeChromium::hasThumb(Scrollbar* scrollbar) -
trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromium.h
r80353 r95860 41 41 // Windows and Linux. 42 42 class ScrollbarThemeChromium : public ScrollbarThemeComposite { 43 #if ENABLE(RUBBER_BANDING) 44 public: 45 ScrollbarThemeChromium(); 46 virtual ~ScrollbarThemeChromium(); 47 virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect); 48 #endif 49 43 50 protected: 44 51 virtual bool hasButtons(Scrollbar*) { return true; } … … 53 60 54 61 virtual IntSize buttonSize(Scrollbar*) = 0; 62 63 #if ENABLE(RUBBER_BANDING) 64 private: 65 RefPtr<Pattern> m_overhangPattern; 66 #endif 55 67 }; 56 68 } // namespace WebCore -
trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.h
r93361 r95860 63 63 void setNewPainterForScrollbar(Scrollbar*, WKScrollbarPainterRef); 64 64 WKScrollbarPainterRef painterForScrollbar(Scrollbar*); 65 66 virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);67 65 68 66 protected: … … 83 81 private: 84 82 void paintGivenTickmarks(GraphicsContext*, Scrollbar*, const IntRect&, const Vector<IntRect>&); 85 86 private:87 RefPtr<Pattern> m_overhangPattern;88 83 }; 89 84 -
trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm
r94275 r95860 195 195 initialized = true; 196 196 197 // Load the linen pattern image used for overhang drawing.198 RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern");199 m_overhangPattern = Pattern::create(patternImage, true, true);200 201 197 [ScrollbarPrefsObserver registerAsObserver]; 202 198 preferencesChanged(); … … 677 673 } 678 674 679 void ScrollbarThemeChromiumMac::paintOverhangAreas(ScrollView* view, GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect) 680 { 681 // The extent of each shadow in pixels. 682 const int kShadowSize = 4; 683 // Offset of negative one pixel to make the gradient blend with the toolbar's bottom border. 684 const int kToolbarShadowOffset = -1; 685 const struct { 686 float stop; 687 Color color; 688 } kShadowColors[] = { 689 { 0.000, Color(0, 0, 0, 255) }, 690 { 0.125, Color(0, 0, 0, 57) }, 691 { 0.375, Color(0, 0, 0, 41) }, 692 { 0.625, Color(0, 0, 0, 18) }, 693 { 0.875, Color(0, 0, 0, 6) }, 694 { 1.000, Color(0, 0, 0, 0) } 695 }; 696 const unsigned kNumShadowColors = sizeof(kShadowColors)/sizeof(kShadowColors[0]); 697 698 const bool hasHorizontalOverhang = !horizontalOverhangRect.isEmpty(); 699 const bool hasVerticalOverhang = !verticalOverhangRect.isEmpty(); 700 // Prefer non-additive shadows, but degrade to additive shadows if there is vertical overhang. 701 const bool useAdditiveShadows = hasVerticalOverhang; 702 703 GraphicsContextStateSaver stateSaver(*context); 704 705 context->setFillPattern(m_overhangPattern); 706 if (hasHorizontalOverhang) 707 context->fillRect(intersection(horizontalOverhangRect, dirtyRect)); 708 if (hasVerticalOverhang) 709 context->fillRect(intersection(verticalOverhangRect, dirtyRect)); 710 711 IntSize scrollOffset = view->scrollOffset(); 712 FloatPoint shadowCornerOrigin; 713 FloatPoint shadowCornerOffset; 714 715 // Draw the shadow for the horizontal overhang. 716 if (hasHorizontalOverhang) { 717 int toolbarShadowHeight = kShadowSize; 718 RefPtr<Gradient> gradient; 719 IntRect shadowRect = horizontalOverhangRect; 720 shadowRect.setHeight(kShadowSize); 721 if (scrollOffset.height() < 0) { 722 if (useAdditiveShadows) { 723 toolbarShadowHeight = std::min(horizontalOverhangRect.height(), kShadowSize); 724 } else if (horizontalOverhangRect.height() < 2 * kShadowSize + kToolbarShadowOffset) { 725 // Split the overhang area between the web content shadow and toolbar shadow if it's too small. 726 shadowRect.setHeight((horizontalOverhangRect.height() + 1) / 2); 727 toolbarShadowHeight = horizontalOverhangRect.height() - shadowRect.height() - kToolbarShadowOffset; 728 } 729 shadowRect.setY(horizontalOverhangRect.maxY() - shadowRect.height()); 730 gradient = Gradient::create(FloatPoint(0, shadowRect.maxY()), FloatPoint(0, shadowRect.maxY() - kShadowSize)); 731 shadowCornerOrigin.setY(shadowRect.maxY()); 732 shadowCornerOffset.setY(-kShadowSize); 733 } else { 734 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY())); 735 shadowCornerOrigin.setY(shadowRect.y()); 736 } 737 if (hasVerticalOverhang) { 738 shadowRect.setWidth(shadowRect.width() - verticalOverhangRect.width()); 739 if (scrollOffset.width() < 0) { 740 shadowRect.setX(shadowRect.x() + verticalOverhangRect.width()); 741 shadowCornerOrigin.setX(shadowRect.x()); 742 shadowCornerOffset.setX(-kShadowSize); 743 } else { 744 shadowCornerOrigin.setX(shadowRect.maxX()); 745 } 746 } 747 for (unsigned i = 0; i < kNumShadowColors; i++) 748 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 749 context->setFillGradient(gradient); 750 context->fillRect(intersection(shadowRect, dirtyRect)); 751 752 // Draw a drop-shadow from the toolbar. 753 if (scrollOffset.height() < 0) { 754 shadowRect.setY(kToolbarShadowOffset); 755 shadowRect.setHeight(toolbarShadowHeight); 756 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.y() + kShadowSize)); 757 for (unsigned i = 0; i < kNumShadowColors; i++) 758 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 759 context->setFillGradient(gradient); 760 context->fillRect(intersection(shadowRect, dirtyRect)); 761 } 762 } 763 764 // Draw the shadow for the vertical overhang. 765 if (hasVerticalOverhang) { 766 RefPtr<Gradient> gradient; 767 IntRect shadowRect = verticalOverhangRect; 768 shadowRect.setWidth(kShadowSize); 769 if (scrollOffset.width() < 0) { 770 shadowRect.setX(verticalOverhangRect.maxX() - shadowRect.width()); 771 gradient = Gradient::create(FloatPoint(shadowRect.maxX(), 0), FloatPoint(shadowRect.x(), 0)); 772 } else { 773 gradient = Gradient::create(FloatPoint(shadowRect.x(), 0), FloatPoint(shadowRect.maxX(), 0)); 774 } 775 for (unsigned i = 0; i < kNumShadowColors; i++) 776 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 777 context->setFillGradient(gradient); 778 context->fillRect(intersection(shadowRect, dirtyRect)); 779 780 // Draw a drop-shadow from the toolbar. 781 shadowRect = verticalOverhangRect; 782 shadowRect.setY(kToolbarShadowOffset); 783 shadowRect.setHeight(kShadowSize); 784 gradient = Gradient::create(FloatPoint(0, shadowRect.y()), FloatPoint(0, shadowRect.maxY())); 785 for (unsigned i = 0; i < kNumShadowColors; i++) 786 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 787 context->setFillGradient(gradient); 788 context->fillRect(intersection(shadowRect, dirtyRect)); 789 } 790 791 // If both rectangles present, draw a radial gradient for the corner. 792 if (hasHorizontalOverhang && hasVerticalOverhang) { 793 RefPtr<Gradient> gradient = Gradient::create(shadowCornerOrigin, 0, shadowCornerOrigin, kShadowSize); 794 for (unsigned i = 0; i < kNumShadowColors; i++) 795 gradient->addColorStop(kShadowColors[i].stop, kShadowColors[i].color); 796 context->setFillGradient(gradient); 797 context->fillRect(FloatRect(shadowCornerOrigin.x() + shadowCornerOffset.x(), shadowCornerOrigin.y() + shadowCornerOffset.y(), kShadowSize, kShadowSize)); 798 } 799 } 800 801 802 } 675 } -
trunk/Source/WebKit/chromium/ChangeLog
r95850 r95860 1 2011-09-23 Fady Samuel <fsamuel@chromium.org> 2 3 Refactor paintOverhangAreas to allow non-Mac Chromium platforms to reuse code 4 https://bugs.webkit.org/show_bug.cgi?id=68648 5 6 Reviewed by Dimitri Glazkov. 7 8 * features.gypi: 9 1 10 2011-09-23 Elliot Poger <epoger@google.com> 2 11 -
trunk/Source/WebKit/chromium/features.gypi
r95514 r95860 141 141 ['touchui==1', { 142 142 'enable_touch_icon_loading': 1, 143 'feature_defines': [ 144 'ENABLE_RUBBER_BANDING=1', 145 ], 143 146 }], 144 147 # Mac OS X uses Accelerate.framework FFT by default instead of FFmpeg.
Note: See TracChangeset
for help on using the changeset viewer.