1 /* 2 * Copyright (c) 2008, 2009, Google 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 are 6 * met: 7 * 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 13 * distribution. 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. 17 * 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. 29 */ 30 31 #include "config.h" 32 #include "ScrollbarThemeChromiumLinux.h" 33 34 #include "PlatformBridge.h" 35 #include "PlatformMouseEvent.h" 36 #include "Scrollbar.h" 37 38 namespace WebCore { 39 40 ScrollbarTheme* ScrollbarTheme::nativeTheme() 41 { 42 static ScrollbarThemeChromiumLinux theme; 43 return &theme; 44 } 45 46 int ScrollbarThemeChromiumLinux::scrollbarThickness(ScrollbarControlSize controlSize) 47 { 48 // Horiz and Vert scrollbars are the same thickness. 49 IntSize scrollbarSize = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarVerticalTrack); 50 return scrollbarSize.width(); 51 } 52 53 void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType) 54 { 55 PlatformBridge::ThemePaintState state = scrollbar->hoveredPart() == partType ? PlatformBridge::StateHover : PlatformBridge::StateNormal; 56 IntRect alignRect = trackRect(scrollbar, false); 57 PlatformBridge::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 PlatformBridge::paintThemePart( 63 gc, 64 scrollbar->orientation() == HorizontalScrollbar ? PlatformBridge::PartScrollbarHorizontalTrack : PlatformBridge::PartScrollbarVerticalTrack, 65 state, 66 rect, 67 &extraParams); 68 } 69 70 void ScrollbarThemeChromiumLinux::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) 71 { 72 PlatformBridge::ThemePart paintPart; 73 PlatformBridge::ThemePaintState state = PlatformBridge::StateNormal; 74 bool checkMin = false; 75 bool checkMax = false; 76 if (scrollbar->orientation() == HorizontalScrollbar) { 77 if (part == BackButtonStartPart) { 78 paintPart = PlatformBridge::PartScrollbarLeftArrow; 79 checkMin = true; 80 } else { 81 paintPart = PlatformBridge::PartScrollbarRightArrow; 82 checkMax = true; 83 } 84 } else { 85 if (part == BackButtonStartPart) { 86 paintPart = PlatformBridge::PartScrollbarUpArrow; 87 checkMin = true; 88 } else { 89 paintPart = PlatformBridge::PartScrollbarDownArrow; 90 checkMax = true; 91 } 92 } 93 if ((checkMin && (scrollbar->currentPos() <= 0)) 94 || (checkMax && scrollbar->currentPos() == scrollbar->maximum())) { 95 state = PlatformBridge::StateDisabled; 96 } else { 97 if (part == scrollbar->pressedPart()) 98 state = PlatformBridge::StatePressed; 99 else if (part == scrollbar->hoveredPart()) 100 state = PlatformBridge::StateHover; 101 } 102 PlatformBridge::paintThemePart(gc, paintPart, state, rect, 0); 103 } 104 105 void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect) 106 { 107 PlatformBridge::ThemePaintState state; 108 109 if (scrollbar->pressedPart() == ThumbPart) 110 state = PlatformBridge::StatePressed; 111 else if (scrollbar->hoveredPart() == ThumbPart) 112 state = PlatformBridge::StateHover; 113 else 114 state = PlatformBridge::StateNormal; 115 PlatformBridge::paintThemePart( 116 gc, 117 scrollbar->orientation() == HorizontalScrollbar ? PlatformBridge::PartScrollbarHorizontalThumb : PlatformBridge::PartScrollbarVerticalThumb, 118 state, 119 rect, 120 0); 121 } 122 123 bool ScrollbarThemeChromiumLinux::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt) 124 { 125 return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == MiddleButton); 126 } 127 128 IntSize ScrollbarThemeChromiumLinux::buttonSize(Scrollbar* scrollbar) 129 { 130 if (scrollbar->orientation() == VerticalScrollbar) { 131 IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarUpArrow); 132 return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? scrollbar->height() / 2 : size.height()); 133 } 134 135 // HorizontalScrollbar 136 IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarLeftArrow); 137 return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() / 2 : size.width(), size.height()); 138 } 139 140 int ScrollbarThemeChromiumLinux::minimumThumbLength(Scrollbar* scrollbar) 141 { 142 if (scrollbar->orientation() == VerticalScrollbar) { 143 IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarVerticalThumb); 144 return size.height(); 145 } 146 147 IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarHorizontalThumb); 148 return size.width(); 149 } 150 151 } // namespace WebCore 152