Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "webkit/glue/webthemeengine_impl_mac.h"
      6 
      7 #include <Carbon/Carbon.h>
      8 
      9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
     10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
     11 
     12 using WebKit::WebCanvas;
     13 using WebKit::WebRect;
     14 using WebKit::WebThemeEngine;
     15 
     16 namespace webkit_glue {
     17 
     18 static ThemeTrackEnableState stateToHIEnableState(WebThemeEngine::State state) {
     19   switch (state) {
     20     case WebThemeEngine::StateDisabled:
     21       return kThemeTrackDisabled;
     22     case WebThemeEngine::StateInactive:
     23       return kThemeTrackInactive;
     24     default:
     25       return kThemeTrackActive;
     26   }
     27 }
     28 
     29 void WebThemeEngineImpl::paintScrollbarThumb(
     30     WebCanvas* canvas,
     31     WebThemeEngine::State state,
     32     WebThemeEngine::Size size,
     33     const WebRect& rect,
     34     const WebThemeEngine::ScrollbarInfo& scrollbarInfo) {
     35   HIThemeTrackDrawInfo trackInfo;
     36   trackInfo.version = 0;
     37   trackInfo.kind = size == WebThemeEngine::SizeRegular ?
     38       kThemeMediumScrollBar : kThemeSmallScrollBar;
     39   trackInfo.bounds = CGRectMake(rect.x, rect.y, rect.width, rect.height);
     40   trackInfo.min = 0;
     41   trackInfo.max = scrollbarInfo.maxValue;
     42   trackInfo.value = scrollbarInfo.currentValue;
     43   trackInfo.trackInfo.scrollbar.viewsize = scrollbarInfo.visibleSize;
     44   trackInfo.attributes = 0;
     45   if (scrollbarInfo.orientation ==
     46       WebThemeEngine::ScrollbarOrientationHorizontal) {
     47     trackInfo.attributes |= kThemeTrackHorizontal;
     48   }
     49 
     50   trackInfo.enableState = stateToHIEnableState(state);
     51 
     52   trackInfo.trackInfo.scrollbar.pressState =
     53       state == WebThemeEngine::StatePressed ? kThemeThumbPressed : 0;
     54   trackInfo.attributes |= (kThemeTrackShowThumb | kThemeTrackHideTrack);
     55   HIThemeDrawTrack(&trackInfo, 0, canvas, kHIThemeOrientationNormal);
     56 }
     57 
     58 }  // namespace webkit_glue
     59