2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "ScrollbarThemeChromiumLinux.h"
34 #include "PlatformSupport.h"
35 #include "PlatformMouseEvent.h"
36 #include "Scrollbar.h"
40 ScrollbarTheme* ScrollbarTheme::nativeTheme()
42 static ScrollbarThemeChromiumLinux theme;
46 int ScrollbarThemeChromiumLinux::scrollbarThickness(ScrollbarControlSize controlSize)
48 // Horiz and Vert scrollbars are the same thickness.
49 IntSize scrollbarSize = PlatformSupport::getThemePartSize(PlatformSupport::PartScrollbarVerticalTrack);
50 return scrollbarSize.width();
53 void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
55 PlatformSupport::ThemePaintState state = scrollbar->hoveredPart() == partType ? PlatformSupport::StateHover : PlatformSupport::StateNormal;
56 IntRect alignRect = trackRect(scrollbar, false);
57 PlatformSupport::ThemePaintExtraParams extraParams;
58 extraParams.scrollbarTrack.trackX = alignRect.x();
59 extraParams.scrollbarTrack.trackY = alignRect.y();
60 extraParams.scrollbarTrack.trackWidth = alignRect.width();
61 extraParams.scrollbarTrack.trackHeight = alignRect.height();
62 PlatformSupport::paintThemePart(
64 scrollbar->orientation() == HorizontalScrollbar ? PlatformSupport::PartScrollbarHorizontalTrack : PlatformSupport::PartScrollbarVerticalTrack,
70 void ScrollbarThemeChromiumLinux::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
72 PlatformSupport::ThemePart paintPart;
73 PlatformSupport::ThemePaintState state = PlatformSupport::StateNormal;
74 bool checkMin = false;
75 bool checkMax = false;
76 if (scrollbar->orientation() == HorizontalScrollbar) {
77 if (part == BackButtonStartPart) {
78 paintPart = PlatformSupport::PartScrollbarLeftArrow;
81 paintPart = PlatformSupport::PartScrollbarRightArrow;
85 if (part == BackButtonStartPart) {
86 paintPart = PlatformSupport::PartScrollbarUpArrow;
89 paintPart = PlatformSupport::PartScrollbarDownArrow;
93 if ((checkMin && (scrollbar->currentPos() <= 0))
94 || (checkMax && scrollbar->currentPos() == scrollbar->maximum())) {
95 state = PlatformSupport::StateDisabled;
97 if (part == scrollbar->pressedPart())
98 state = PlatformSupport::StatePressed;
99 else if (part == scrollbar->hoveredPart())
100 state = PlatformSupport::StateHover;
102 PlatformSupport::paintThemePart(gc, paintPart, state, rect, 0);
105 void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
107 PlatformSupport::ThemePaintState state;
109 if (scrollbar->pressedPart() == ThumbPart)
110 state = PlatformSupport::StatePressed;
111 else if (scrollbar->hoveredPart() == ThumbPart)
112 state = PlatformSupport::StateHover;
114 state = PlatformSupport::StateNormal;
115 PlatformSupport::paintThemePart(
117 scrollbar->orientation() == HorizontalScrollbar ? PlatformSupport::PartScrollbarHorizontalThumb : PlatformSupport::PartScrollbarVerticalThumb,
123 bool ScrollbarThemeChromiumLinux::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt)
125 return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == MiddleButton);
128 IntSize ScrollbarThemeChromiumLinux::buttonSize(Scrollbar* scrollbar)
130 if (scrollbar->orientation() == VerticalScrollbar) {
131 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartScrollbarUpArrow);
132 return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? scrollbar->height() / 2 : size.height());
135 // HorizontalScrollbar
136 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartScrollbarLeftArrow);
137 return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() / 2 : size.width(), size.height());
140 int ScrollbarThemeChromiumLinux::minimumThumbLength(Scrollbar* scrollbar)
142 if (scrollbar->orientation() == VerticalScrollbar) {
143 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartScrollbarVerticalThumb);
144 return size.height();
147 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartScrollbarHorizontalThumb);
151 } // namespace WebCore