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