Demonstrate the basic functionality of the File System
[chromium-blink-merge.git] / ui / views / controls / scrollbar / native_scroll_bar.cc
blob7b45dd6e05247429945ec235ebc1b05aefa18c4e
1 // Copyright (c) 2012 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.
5 #include "ui/views/controls/scrollbar/native_scroll_bar.h"
7 #include <algorithm>
8 #include <string>
10 #include "base/message_loop/message_loop.h"
11 #include "ui/events/event.h"
12 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
13 #include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h"
14 #include "ui/views/widget/widget.h"
16 namespace views {
18 // static
19 const char NativeScrollBar::kViewClassName[] = "NativeScrollBar";
21 ////////////////////////////////////////////////////////////////////////////////
22 // NativeScrollBar, public:
23 NativeScrollBar::NativeScrollBar(bool is_horizontal)
24 : ScrollBar(is_horizontal),
25 native_wrapper_(NULL) {
28 NativeScrollBar::~NativeScrollBar() {
31 // static
32 int NativeScrollBar::GetHorizontalScrollBarHeight(
33 const ui::NativeTheme* theme) {
34 return NativeScrollBarWrapper::GetHorizontalScrollBarHeight(theme);
37 // static
38 int NativeScrollBar::GetVerticalScrollBarWidth(
39 const ui::NativeTheme* theme) {
40 return NativeScrollBarWrapper::GetVerticalScrollBarWidth(theme);
43 ////////////////////////////////////////////////////////////////////////////////
44 // NativeScrollBar, View overrides:
45 gfx::Size NativeScrollBar::GetPreferredSize() const {
46 if (native_wrapper_)
47 return native_wrapper_->GetView()->GetPreferredSize();
48 return gfx::Size();
51 void NativeScrollBar::Layout() {
52 if (native_wrapper_) {
53 native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
54 native_wrapper_->GetView()->Layout();
58 void NativeScrollBar::ViewHierarchyChanged(
59 const ViewHierarchyChangedDetails& details) {
60 Widget* widget;
61 if (details.is_add && !native_wrapper_ && (widget = GetWidget())) {
62 native_wrapper_ = NativeScrollBarWrapper::CreateWrapper(this);
63 AddChildView(native_wrapper_->GetView());
67 const char* NativeScrollBar::GetClassName() const {
68 return kViewClassName;
71 // Overridden from View for keyboard UI.
72 bool NativeScrollBar::OnKeyPressed(const ui::KeyEvent& event) {
73 if (!native_wrapper_)
74 return false;
75 return native_wrapper_->GetView()->OnKeyPressed(event);
78 void NativeScrollBar::OnGestureEvent(ui::GestureEvent* event) {
79 if (!native_wrapper_)
80 return;
81 native_wrapper_->GetView()->OnGestureEvent(event);
84 bool NativeScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) {
85 if (!native_wrapper_)
86 return false;
87 return native_wrapper_->GetView()->OnMouseWheel(event);
90 ////////////////////////////////////////////////////////////////////////////////
91 // NativeScrollBar, ScrollBar overrides:
92 void NativeScrollBar::Update(int viewport_size,
93 int content_size,
94 int current_pos) {
95 ScrollBar::Update(viewport_size, content_size, current_pos);
97 if (native_wrapper_)
98 native_wrapper_->Update(viewport_size, content_size, current_pos);
101 int NativeScrollBar::GetLayoutSize() const {
102 return IsHorizontal() ?
103 GetHorizontalScrollBarHeight(GetNativeTheme()) :
104 GetVerticalScrollBarWidth(GetNativeTheme());
107 int NativeScrollBar::GetPosition() const {
108 if (!native_wrapper_)
109 return 0;
110 return native_wrapper_->GetPosition();
113 } // namespace views