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 "RenderScrollbarTheme.h" 28#include "RenderScrollbar.h" 29#include <wtf/StdLibExtras.h> 30 31namespace WebCore { 32 33RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme() 34{ 35 DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ()); 36 return &theme; 37} 38 39void RenderScrollbarTheme::buttonSizesAlongTrackAxis(Scrollbar* scrollbar, int& beforeSize, int& afterSize) 40{ 41 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart); 42 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart); 43 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart); 44 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart); 45 if (scrollbar->orientation() == HorizontalScrollbar) { 46 beforeSize = firstButton.width() + secondButton.width(); 47 afterSize = thirdButton.width() + fourthButton.width(); 48 } else { 49 beforeSize = firstButton.height() + secondButton.height(); 50 afterSize = thirdButton.height() + fourthButton.height(); 51 } 52} 53 54bool RenderScrollbarTheme::hasButtons(Scrollbar* scrollbar) 55{ 56 int startSize; 57 int endSize; 58 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize); 59 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrollbar ? scrollbar->width() : scrollbar->height()); 60} 61 62bool RenderScrollbarTheme::hasThumb(Scrollbar* scrollbar) 63{ 64 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0; 65} 66 67int RenderScrollbarTheme::minimumThumbLength(Scrollbar* scrollbar) 68{ 69 return toRenderScrollbar(scrollbar)->minimumThumbLength(); 70} 71 72IntRect RenderScrollbarTheme::backButtonRect(Scrollbar* scrollbar, ScrollbarPart partType, bool) 73{ 74 return toRenderScrollbar(scrollbar)->buttonRect(partType); 75} 76 77IntRect RenderScrollbarTheme::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart partType, bool) 78{ 79 return toRenderScrollbar(scrollbar)->buttonRect(partType); 80} 81 82IntRect RenderScrollbarTheme::trackRect(Scrollbar* scrollbar, bool) 83{ 84 if (!hasButtons(scrollbar)) 85 return scrollbar->frameRect(); 86 87 int startLength; 88 int endLength; 89 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength); 90 91 return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength); 92} 93 94IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(Scrollbar* scrollbar, const IntRect& rect) 95{ 96 IntRect backRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(BackTrackPart, rect); 97 IntRect forwardRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(ForwardTrackPart, rect); 98 IntRect result = rect; 99 if (scrollbar->orientation() == HorizontalScrollbar) { 100 result.setX(backRect.x()); 101 result.setWidth(forwardRect.maxX() - backRect.x()); 102 } else { 103 result.setY(backRect.y()); 104 result.setHeight(forwardRect.maxY() - backRect.y()); 105 } 106 return result; 107} 108 109void RenderScrollbarTheme::paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect) 110{ 111 // FIXME: Implement. 112 context->fillRect(cornerRect, Color::white, ColorSpaceDeviceRGB); 113} 114 115void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar) 116{ 117 toRenderScrollbar(scrollbar)->paintPart(context, ScrollbarBGPart, scrollbar->frameRect()); 118} 119 120void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) 121{ 122 toRenderScrollbar(scrollbar)->paintPart(context, TrackBGPart, rect); 123} 124 125void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) 126{ 127 toRenderScrollbar(scrollbar)->paintPart(context, part, rect); 128} 129 130void RenderScrollbarTheme::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) 131{ 132 toRenderScrollbar(scrollbar)->paintPart(context, part, rect); 133} 134 135void RenderScrollbarTheme::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) 136{ 137 toRenderScrollbar(scrollbar)->paintPart(context, ThumbPart, rect); 138} 139 140} 141