| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/rendering/RenderScrollbarTheme.h" | 27 #include "core/layout/LayoutScrollbarTheme.h" |
| 28 | 28 |
| 29 #include "core/layout/LayoutScrollbar.h" |
| 29 #include "core/paint/ScrollbarPainter.h" | 30 #include "core/paint/ScrollbarPainter.h" |
| 30 #include "core/rendering/RenderScrollbar.h" | |
| 31 #include "platform/graphics/GraphicsContext.h" | 31 #include "platform/graphics/GraphicsContext.h" |
| 32 #include "platform/graphics/paint/DrawingRecorder.h" | 32 #include "platform/graphics/paint/DrawingRecorder.h" |
| 33 #include "platform/scroll/ScrollbarThemeClient.h" | 33 #include "platform/scroll/ScrollbarThemeClient.h" |
| 34 #include "wtf/StdLibExtras.h" | 34 #include "wtf/StdLibExtras.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme() | 38 LayoutScrollbarTheme* LayoutScrollbarTheme::renderScrollbarTheme() |
| 39 { | 39 { |
| 40 DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ()); | 40 DEFINE_STATIC_LOCAL(LayoutScrollbarTheme, theme, ()); |
| 41 return &theme; | 41 return &theme; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void RenderScrollbarTheme::buttonSizesAlongTrackAxis(ScrollbarThemeClient* scrol
lbar, int& beforeSize, int& afterSize) | 44 void LayoutScrollbarTheme::buttonSizesAlongTrackAxis(ScrollbarThemeClient* scrol
lbar, int& beforeSize, int& afterSize) |
| 45 { | 45 { |
| 46 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart); | 46 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart); |
| 47 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart); | 47 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart); |
| 48 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart); | 48 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart); |
| 49 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart); | 49 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart); |
| 50 if (scrollbar->orientation() == HorizontalScrollbar) { | 50 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 51 beforeSize = firstButton.width() + secondButton.width(); | 51 beforeSize = firstButton.width() + secondButton.width(); |
| 52 afterSize = thirdButton.width() + fourthButton.width(); | 52 afterSize = thirdButton.width() + fourthButton.width(); |
| 53 } else { | 53 } else { |
| 54 beforeSize = firstButton.height() + secondButton.height(); | 54 beforeSize = firstButton.height() + secondButton.height(); |
| 55 afterSize = thirdButton.height() + fourthButton.height(); | 55 afterSize = thirdButton.height() + fourthButton.height(); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool RenderScrollbarTheme::hasButtons(ScrollbarThemeClient* scrollbar) | 59 bool LayoutScrollbarTheme::hasButtons(ScrollbarThemeClient* scrollbar) |
| 60 { | 60 { |
| 61 int startSize; | 61 int startSize; |
| 62 int endSize; | 62 int endSize; |
| 63 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize); | 63 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize); |
| 64 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrol
lbar ? scrollbar->width() : scrollbar->height()); | 64 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrol
lbar ? scrollbar->width() : scrollbar->height()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool RenderScrollbarTheme::hasThumb(ScrollbarThemeClient* scrollbar) | 67 bool LayoutScrollbarTheme::hasThumb(ScrollbarThemeClient* scrollbar) |
| 68 { | 68 { |
| 69 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0; | 69 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0; |
| 70 } | 70 } |
| 71 | 71 |
| 72 int RenderScrollbarTheme::minimumThumbLength(ScrollbarThemeClient* scrollbar) | 72 int LayoutScrollbarTheme::minimumThumbLength(ScrollbarThemeClient* scrollbar) |
| 73 { | 73 { |
| 74 return toRenderScrollbar(scrollbar)->minimumThumbLength(); | 74 return toLayoutScrollbar(scrollbar)->minimumThumbLength(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 IntRect RenderScrollbarTheme::backButtonRect(ScrollbarThemeClient* scrollbar, Sc
rollbarPart partType, bool) | 77 IntRect LayoutScrollbarTheme::backButtonRect(ScrollbarThemeClient* scrollbar, Sc
rollbarPart partType, bool) |
| 78 { | 78 { |
| 79 return toRenderScrollbar(scrollbar)->buttonRect(partType); | 79 return toLayoutScrollbar(scrollbar)->buttonRect(partType); |
| 80 } | 80 } |
| 81 | 81 |
| 82 IntRect RenderScrollbarTheme::forwardButtonRect(ScrollbarThemeClient* scrollbar,
ScrollbarPart partType, bool) | 82 IntRect LayoutScrollbarTheme::forwardButtonRect(ScrollbarThemeClient* scrollbar,
ScrollbarPart partType, bool) |
| 83 { | 83 { |
| 84 return toRenderScrollbar(scrollbar)->buttonRect(partType); | 84 return toLayoutScrollbar(scrollbar)->buttonRect(partType); |
| 85 } | 85 } |
| 86 | 86 |
| 87 IntRect RenderScrollbarTheme::trackRect(ScrollbarThemeClient* scrollbar, bool) | 87 IntRect LayoutScrollbarTheme::trackRect(ScrollbarThemeClient* scrollbar, bool) |
| 88 { | 88 { |
| 89 if (!hasButtons(scrollbar)) | 89 if (!hasButtons(scrollbar)) |
| 90 return scrollbar->frameRect(); | 90 return scrollbar->frameRect(); |
| 91 | 91 |
| 92 int startLength; | 92 int startLength; |
| 93 int endLength; | 93 int endLength; |
| 94 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength); | 94 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength); |
| 95 | 95 |
| 96 return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength); | 96 return toLayoutScrollbar(scrollbar)->trackRect(startLength, endLength); |
| 97 } | 97 } |
| 98 | 98 |
| 99 IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(ScrollbarThemeClie
nt* scrollbar, const IntRect& rect) | 99 IntRect LayoutScrollbarTheme::constrainTrackRectToTrackPieces(ScrollbarThemeClie
nt* scrollbar, const IntRect& rect) |
| 100 { | 100 { |
| 101 IntRect backRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(B
ackTrackPart, rect); | 101 IntRect backRect = toLayoutScrollbar(scrollbar)->trackPieceRectWithMargins(B
ackTrackPart, rect); |
| 102 IntRect forwardRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargin
s(ForwardTrackPart, rect); | 102 IntRect forwardRect = toLayoutScrollbar(scrollbar)->trackPieceRectWithMargin
s(ForwardTrackPart, rect); |
| 103 IntRect result = rect; | 103 IntRect result = rect; |
| 104 if (scrollbar->orientation() == HorizontalScrollbar) { | 104 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 105 result.setX(backRect.x()); | 105 result.setX(backRect.x()); |
| 106 result.setWidth(forwardRect.maxX() - backRect.x()); | 106 result.setWidth(forwardRect.maxX() - backRect.x()); |
| 107 } else { | 107 } else { |
| 108 result.setY(backRect.y()); | 108 result.setY(backRect.y()); |
| 109 result.setHeight(forwardRect.maxY() - backRect.y()); | 109 result.setHeight(forwardRect.maxY() - backRect.y()); |
| 110 } | 110 } |
| 111 return result; | 111 return result; |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool RenderScrollbarTheme::paint(ScrollbarThemeClient* scrollbar, GraphicsContex
t* graphicsContext, const IntRect& damageRect) | 114 bool LayoutScrollbarTheme::paint(ScrollbarThemeClient* scrollbar, GraphicsContex
t* graphicsContext, const IntRect& damageRect) |
| 115 { | 115 { |
| 116 return paintInternal(scrollbar, graphicsContext, damageRect); | 116 return paintInternal(scrollbar, graphicsContext, damageRect); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void RenderScrollbarTheme::paintScrollCorner(GraphicsContext* context, DisplayIt
emClient displayItemClient, const IntRect& cornerRect) | 119 void LayoutScrollbarTheme::paintScrollCorner(GraphicsContext* context, DisplayIt
emClient displayItemClient, const IntRect& cornerRect) |
| 120 { | 120 { |
| 121 DrawingRecorder recorder(context, displayItemClient, DisplayItem::ScrollbarC
orner, cornerRect); | 121 DrawingRecorder recorder(context, displayItemClient, DisplayItem::ScrollbarC
orner, cornerRect); |
| 122 // FIXME: Implement. | 122 // FIXME: Implement. |
| 123 if (!recorder.canUseCachedDrawing()) | 123 if (!recorder.canUseCachedDrawing()) |
| 124 context->fillRect(cornerRect, Color::white); | 124 context->fillRect(cornerRect, Color::white); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, Sc
rollbarThemeClient* scrollbar) | 127 void LayoutScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, Sc
rollbarThemeClient* scrollbar) |
| 128 { | 128 { |
| 129 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, Scrollbar
BGPart, scrollbar->frameRect()); | 129 ScrollbarPainter(*toLayoutScrollbar(scrollbar)).paintPart(context, Scrollbar
BGPart, scrollbar->frameRect()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, Scroll
barThemeClient* scrollbar, const IntRect& rect) | 132 void LayoutScrollbarTheme::paintTrackBackground(GraphicsContext* context, Scroll
barThemeClient* scrollbar, const IntRect& rect) |
| 133 { | 133 { |
| 134 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, TrackBGPa
rt, rect); | 134 ScrollbarPainter(*toLayoutScrollbar(scrollbar)).paintPart(context, TrackBGPa
rt, rect); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, ScrollbarTh
emeClient* scrollbar, const IntRect& rect, ScrollbarPart part) | 137 void LayoutScrollbarTheme::paintTrackPiece(GraphicsContext* context, ScrollbarTh
emeClient* scrollbar, const IntRect& rect, ScrollbarPart part) |
| 138 { | 138 { |
| 139 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, part, rec
t); | 139 ScrollbarPainter(*toLayoutScrollbar(scrollbar)).paintPart(context, part, rec
t); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void RenderScrollbarTheme::paintButton(GraphicsContext* context, ScrollbarThemeC
lient* scrollbar, const IntRect& rect, ScrollbarPart part) | 142 void LayoutScrollbarTheme::paintButton(GraphicsContext* context, ScrollbarThemeC
lient* scrollbar, const IntRect& rect, ScrollbarPart part) |
| 143 { | 143 { |
| 144 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, part, rec
t); | 144 ScrollbarPainter(*toLayoutScrollbar(scrollbar)).paintPart(context, part, rec
t); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void RenderScrollbarTheme::paintThumb(GraphicsContext* context, ScrollbarThemeCl
ient* scrollbar, const IntRect& rect) | 147 void LayoutScrollbarTheme::paintThumb(GraphicsContext* context, ScrollbarThemeCl
ient* scrollbar, const IntRect& rect) |
| 148 { | 148 { |
| 149 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, ThumbPart
, rect); | 149 ScrollbarPainter(*toLayoutScrollbar(scrollbar)).paintPart(context, ThumbPart
, rect); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void RenderScrollbarTheme::paintTickmarks(GraphicsContext* context, ScrollbarThe
meClient* scrollbar, const IntRect& rect) | 152 void LayoutScrollbarTheme::paintTickmarks(GraphicsContext* context, ScrollbarThe
meClient* scrollbar, const IntRect& rect) |
| 153 { | 153 { |
| 154 DrawingRecorder recorder(context, scrollbar->displayItemClient(), DisplayIte
m::ScrollbarTickMark, rect); | 154 DrawingRecorder recorder(context, scrollbar->displayItemClient(), DisplayIte
m::ScrollbarTickMark, rect); |
| 155 if (!recorder.canUseCachedDrawing()) | 155 if (!recorder.canUseCachedDrawing()) |
| 156 ScrollbarTheme::theme()->paintTickmarks(context, scrollbar, rect); | 156 ScrollbarTheme::theme()->paintTickmarks(context, scrollbar, rect); |
| 157 } | 157 } |
| 158 | 158 |
| 159 } | 159 } |
| OLD | NEW |