1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright 2009 Maxime Simon <simon.maxime@gmail.com> All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "config.h"
28 #include "ScrollbarThemeHaiku.h"
29
30 #include "GraphicsContext.h"
31 #include "Scrollbar.h"
32 #include <ControlLook.h>
33 #include <InterfaceDefs.h>
34
35
buttonWidth(int scrollbarWidth,int thickness)36 int buttonWidth(int scrollbarWidth, int thickness)
37 {
38 return scrollbarWidth < 2 * thickness ? scrollbarWidth / 2 : thickness;
39 }
40
41 namespace WebCore {
42
nativeTheme()43 ScrollbarTheme* ScrollbarTheme::nativeTheme()
44 {
45 static ScrollbarThemeHaiku theme;
46 return &theme;
47 }
48
ScrollbarThemeHaiku()49 ScrollbarThemeHaiku::ScrollbarThemeHaiku()
50 {
51 }
52
~ScrollbarThemeHaiku()53 ScrollbarThemeHaiku::~ScrollbarThemeHaiku()
54 {
55 }
56
scrollbarThickness(ScrollbarControlSize controlSize)57 int ScrollbarThemeHaiku::scrollbarThickness(ScrollbarControlSize controlSize)
58 {
59 // FIXME: Should we make a distinction between a Small and a Regular Scrollbar?
60 return 16;
61 }
62
hasButtons(Scrollbar * scrollbar)63 bool ScrollbarThemeHaiku::hasButtons(Scrollbar* scrollbar)
64 {
65 return scrollbar->enabled();
66 }
67
hasThumb(Scrollbar * scrollbar)68 bool ScrollbarThemeHaiku::hasThumb(Scrollbar* scrollbar)
69 {
70 return scrollbar->enabled() && thumbLength(scrollbar) > 0;
71 }
72
backButtonRect(Scrollbar * scrollbar,ScrollbarPart part,bool)73 IntRect ScrollbarThemeHaiku::backButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool)
74 {
75 if (part == BackButtonEndPart)
76 return IntRect();
77
78 int thickness = scrollbarThickness();
79 IntPoint buttonOrigin(scrollbar->x(), scrollbar->y());
80 IntSize buttonSize = scrollbar->orientation() == HorizontalScrollbar
81 ? IntSize(buttonWidth(scrollbar->width(), thickness), thickness)
82 : IntSize(thickness, buttonWidth(scrollbar->height(), thickness));
83 IntRect buttonRect(buttonOrigin, buttonSize);
84
85 return buttonRect;
86 }
87
forwardButtonRect(Scrollbar * scrollbar,ScrollbarPart part,bool)88 IntRect ScrollbarThemeHaiku::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool)
89 {
90 if (part == BackButtonStartPart)
91 return IntRect();
92
93 int thickness = scrollbarThickness();
94 if (scrollbar->orientation() == HorizontalScrollbar) {
95 int width = buttonWidth(scrollbar->width(), thickness);
96 return IntRect(scrollbar->x() + scrollbar->width() - width, scrollbar->y(), width, thickness);
97 }
98
99 int height = buttonWidth(scrollbar->height(), thickness);
100 return IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height() - height, thickness, height);
101 }
102
trackRect(Scrollbar * scrollbar,bool)103 IntRect ScrollbarThemeHaiku::trackRect(Scrollbar* scrollbar, bool)
104 {
105 int thickness = scrollbarThickness();
106 if (scrollbar->orientation() == HorizontalScrollbar) {
107 if (scrollbar->width() < 2 * thickness)
108 return IntRect();
109 return IntRect(scrollbar->x() + thickness, scrollbar->y(), scrollbar->width() - 2 * thickness, thickness);
110 }
111 if (scrollbar->height() < 2 * thickness)
112 return IntRect();
113 return IntRect(scrollbar->x(), scrollbar->y() + thickness, thickness, scrollbar->height() - 2 * thickness);
114 }
115
paintScrollbarBackground(GraphicsContext * context,Scrollbar * scrollbar)116 void ScrollbarThemeHaiku::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar)
117 {
118 if (!be_control_look)
119 return;
120
121 BRect rect = trackRect(scrollbar, false);
122 orientation scrollbarOrientation = scrollbar->orientation() == HorizontalScrollbar ? B_HORIZONTAL : B_VERTICAL;
123
124 be_control_look->DrawScrollBarBackground(context->platformContext(), rect, rect, ui_color(B_PANEL_BACKGROUND_COLOR), 0, scrollbarOrientation);
125 }
126
paintButton(GraphicsContext * context,Scrollbar * scrollbar,const IntRect & rect,ScrollbarPart part)127 void ScrollbarThemeHaiku::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
128 {
129 if (!be_control_look)
130 return;
131
132 BRect drawRect = BRect(rect);
133 BView* view = context->platformContext();
134 rgb_color panelBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
135 rgb_color buttonBgColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT);
136
137 be_control_look->DrawButtonFrame(view, drawRect, drawRect, buttonBgColor, panelBgColor);
138 be_control_look->DrawButtonBackground(view, drawRect, drawRect, buttonBgColor);
139
140 int arrowDirection;
141 if (scrollbar->orientation() == VerticalScrollbar)
142 arrowDirection = part == BackButtonStartPart ? BControlLook::B_UP_ARROW : BControlLook::B_DOWN_ARROW;
143 else
144 arrowDirection = part == BackButtonStartPart ? BControlLook::B_LEFT_ARROW : BControlLook::B_RIGHT_ARROW;
145
146 be_control_look->DrawArrowShape(view, drawRect, drawRect, ui_color(B_CONTROL_TEXT_COLOR), arrowDirection);
147 }
148
paintThumb(GraphicsContext * context,Scrollbar *,const IntRect & rect)149 void ScrollbarThemeHaiku::paintThumb(GraphicsContext* context, Scrollbar*, const IntRect& rect)
150 {
151 if (!be_control_look)
152 return;
153
154 BRect drawRect = BRect(rect);
155 BView* view = context->platformContext();
156 rgb_color panelBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
157 rgb_color buttonBgColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT);
158
159 be_control_look->DrawButtonFrame(view, drawRect, drawRect, buttonBgColor, panelBgColor);
160 be_control_look->DrawButtonBackground(view, drawRect, drawRect, buttonBgColor);
161 }
162
163 }
164
165