summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webthemeengine_impl_mac.cc
blob: cafc316639b7131a4ac5619330436cc1f0caa5fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/glue/webthemeengine_impl_mac.h"

#include <Carbon/Carbon.h>

#include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"

using WebKit::WebCanvas;
using WebKit::WebRect;
using WebKit::WebThemeEngine;

namespace webkit_glue {

static ThemeTrackEnableState stateToHIEnableState(WebThemeEngine::State state) {
  switch (state) {
    case WebThemeEngine::StateDisabled:
      return kThemeTrackDisabled;
    case WebThemeEngine::StateInactive:
      return kThemeTrackInactive;
    default:
      return kThemeTrackActive;
  }
}

void WebThemeEngineImpl::paintScrollbarThumb(
    WebCanvas* canvas,
    WebThemeEngine::State state,
    WebThemeEngine::Size size,
    const WebRect& rect,
    const WebThemeEngine::ScrollbarInfo& scrollbarInfo) {
  HIThemeTrackDrawInfo trackInfo;
  trackInfo.version = 0;
  trackInfo.kind = size == WebThemeEngine::SizeRegular ?
      kThemeMediumScrollBar : kThemeSmallScrollBar;
  trackInfo.bounds = CGRectMake(rect.x, rect.y, rect.width, rect.height);
  trackInfo.min = 0;
  trackInfo.max = scrollbarInfo.maxValue;
  trackInfo.value = scrollbarInfo.currentValue;
  trackInfo.trackInfo.scrollbar.viewsize = scrollbarInfo.visibleSize;
  trackInfo.attributes = 0;
  if (scrollbarInfo.orientation ==
      WebThemeEngine::ScrollbarOrientationHorizontal) {
    trackInfo.attributes |= kThemeTrackHorizontal;
  }

  trackInfo.enableState = stateToHIEnableState(state);

  trackInfo.trackInfo.scrollbar.pressState =
      state == WebThemeEngine::StatePressed ? kThemeThumbPressed : 0;
  trackInfo.attributes |= (kThemeTrackShowThumb | kThemeTrackHideTrack);
  HIThemeDrawTrack(&trackInfo, 0, canvas, kHIThemeOrientationNormal);
}

}  // namespace webkit_glue