summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webthemeengine_impl_linux.cc
blob: d5cc9b44b2e82427d699ebcaba7cba5bec04cb15 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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_linux.h"

#include "gfx/native_theme_linux.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"

using WebKit::WebCanvas;
using WebKit::WebColor;
using WebKit::WebRect;

namespace webkit_glue {

static gfx::Rect WebRectToRect(const WebRect& rect) {
  return gfx::Rect(rect.x, rect.y, rect.width, rect.height);
}

static gfx::NativeThemeLinux::Part NativeThemePart(
    WebKit::WebThemeEngine::Part part) {
  switch (part) {
    case WebKit::WebThemeEngine::PartScrollbarDownArrow:
      return gfx::NativeThemeLinux::kScrollbarDownArrow;
    case WebKit::WebThemeEngine::PartScrollbarLeftArrow:
      return gfx::NativeThemeLinux::kScrollbarLeftArrow;
    case WebKit::WebThemeEngine::PartScrollbarRightArrow:
      return gfx::NativeThemeLinux::kScrollbarRightArrow;
    case WebKit::WebThemeEngine::PartScrollbarUpArrow:
      return gfx::NativeThemeLinux::kScrollbarUpArrow;
    case WebKit::WebThemeEngine::PartScrollbarHorizontalThumb:
      return gfx::NativeThemeLinux::kScrollbarHorizontalThumb;
    case WebKit::WebThemeEngine::PartScrollbarVerticalThumb:
      return gfx::NativeThemeLinux::kScrollbarVerticalThumb;
    case WebKit::WebThemeEngine::PartScrollbarHoriztonalTrack:
      return gfx::NativeThemeLinux::kScrollbarHorizontalTrack;
    case WebKit::WebThemeEngine::PartScrollbarVerticalTrack:
      return gfx::NativeThemeLinux::kScrollbarVerticalTrack;
    default:
      return gfx::NativeThemeLinux::kScrollbarDownArrow;
  }
}

static gfx::NativeThemeLinux::State NativeThemeState(
    WebKit::WebThemeEngine::State state) {
  switch (state) {
    case WebKit::WebThemeEngine::StateDisabled:
      return gfx::NativeThemeLinux::kDisabled;
    case WebKit::WebThemeEngine::StateHover:
      return gfx::NativeThemeLinux::kHover;
    case WebKit::WebThemeEngine::StateNormal:
      return gfx::NativeThemeLinux::kNormal;
    case WebKit::WebThemeEngine::StatePressed:
      return gfx::NativeThemeLinux::kPressed;
    default:
      return gfx::NativeThemeLinux::kDisabled;
  }
}

static void GetNativeThemeExtraParams(
    WebKit::WebThemeEngine::Part part,
    WebKit::WebThemeEngine::State state,
    const WebKit::WebThemeEngine::ExtraParams* extra_params,
    gfx::NativeThemeLinux::ExtraParams* native_theme_extra_params) {
  if (part == WebKit::WebThemeEngine::PartScrollbarHoriztonalTrack ||
      part == WebKit::WebThemeEngine::PartScrollbarVerticalTrack) {
    native_theme_extra_params->scrollbar_track.track_x =
        extra_params->scrollbarTrack.trackX;
    native_theme_extra_params->scrollbar_track.track_y =
        extra_params->scrollbarTrack.trackY;
    native_theme_extra_params->scrollbar_track.track_width =
        extra_params->scrollbarTrack.trackWidth;
    native_theme_extra_params->scrollbar_track.track_height =
        extra_params->scrollbarTrack.trackHeight;
  }
}

WebKit::WebSize WebThemeEngineImpl::getSize(WebKit::WebThemeEngine::Part part) {
  return gfx::NativeThemeLinux::instance()->GetSize(NativeThemePart(part));
}

void WebThemeEngineImpl::paint(
    WebKit::WebCanvas* canvas,
    WebKit::WebThemeEngine::Part part,
    WebKit::WebThemeEngine::State state,
    const WebKit::WebRect& rect,
    const WebKit::WebThemeEngine::ExtraParams* extra_params) {
  gfx::NativeThemeLinux::ExtraParams native_theme_extra_params;
  GetNativeThemeExtraParams(
      part, state, extra_params, &native_theme_extra_params);
  gfx::NativeThemeLinux::instance()->Paint(
      canvas,
      NativeThemePart(part),
      NativeThemeState(state),
      WebRectToRect(rect),
      native_theme_extra_params);
}
}  // namespace webkit_glue