summaryrefslogtreecommitdiffstats
path: root/views/controls/scrollbar/native_scroll_bar.cc
blob: 39a9120e655c284af256ec960597daee520ddf3d (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
101
// Copyright (c) 2006-2008 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 "views/controls/scrollbar/native_scroll_bar.h"

#include <algorithm>
#include <string>

#include "base/message_loop.h"
#include "views/controls/scrollbar/native_scroll_bar_wrapper.h"
#include "views/widget/widget.h"

namespace views {

// static
const char NativeScrollBar::kViewClassName[] = "views/NativeScrollBar";

////////////////////////////////////////////////////////////////////////////////
// NativeScrollBar, public:
NativeScrollBar::NativeScrollBar(bool is_horizontal)
    : ScrollBar(is_horizontal),
      native_wrapper_(NULL) {
}

NativeScrollBar::~NativeScrollBar() {
}

// static
int NativeScrollBar::GetHorizontalScrollBarHeight() {
  return NativeScrollBarWrapper::GetHorizontalScrollBarHeight();
}

// static
int NativeScrollBar::GetVerticalScrollBarWidth() {
  return NativeScrollBarWrapper::GetVerticalScrollBarWidth();
}

////////////////////////////////////////////////////////////////////////////////
// NativeScrollBar, View overrides:
gfx::Size NativeScrollBar::GetPreferredSize() {
  if (native_wrapper_)
    return native_wrapper_->GetView()->GetPreferredSize();
  return gfx::Size();
}

void NativeScrollBar::Layout() {
  if (native_wrapper_)
    native_wrapper_->GetView()->Layout();
}

void NativeScrollBar::ViewHierarchyChanged(bool is_add, View *parent,
                                           View *child) {
  Widget* widget;
  if (is_add && !native_wrapper_ && (widget = GetWidget())) {
    native_wrapper_ = NativeScrollBarWrapper::CreateWrapper(this);
    AddChildView(native_wrapper_->GetView());
  }
}

std::string NativeScrollBar::GetClassName() const {
  return kViewClassName;
}

// Overridden from View for keyboard UI.
bool NativeScrollBar::OnKeyPressed(const KeyEvent& event) {
  if (!native_wrapper_)
    return false;
  return native_wrapper_->GetView()->OnKeyPressed(event);
}

bool NativeScrollBar::OnMouseWheel(const MouseWheelEvent& event) {
  if (!native_wrapper_)
    return false;
  return native_wrapper_->GetView()->OnMouseWheel(event);
}

////////////////////////////////////////////////////////////////////////////////
// NativeScrollBar, ScrollBar overrides:
void NativeScrollBar::Update(int viewport_size,
                             int content_size,
                             int current_pos) {
  ScrollBar::Update(viewport_size, content_size, current_pos);

  if (native_wrapper_)
    native_wrapper_->Update(viewport_size, content_size, current_pos);
}

int NativeScrollBar::GetLayoutSize() const {
  return IsHorizontal() ?
      GetHorizontalScrollBarHeight() : GetVerticalScrollBarWidth();
}

int NativeScrollBar::GetPosition() const {
  if (!native_wrapper_)
    return 0;
  return native_wrapper_->GetPosition();
}

}  // namespace views