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"
10 #include "base/message_loop/message_loop.h"
11 #include "ui/events/event.h"
12 #include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h"
13 #include "ui/views/widget/widget.h"
16 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
22 const char NativeScrollBar::kViewClassName[] = "NativeScrollBar";
24 ////////////////////////////////////////////////////////////////////////////////
25 // NativeScrollBar, public:
26 NativeScrollBar::NativeScrollBar(bool is_horizontal)
27 : ScrollBar(is_horizontal),
28 native_wrapper_(NULL) {
31 NativeScrollBar::~NativeScrollBar() {
35 int NativeScrollBar::GetHorizontalScrollBarHeight(
36 const ui::NativeTheme* theme) {
37 return NativeScrollBarWrapper::GetHorizontalScrollBarHeight(theme);
41 int NativeScrollBar::GetVerticalScrollBarWidth(
42 const ui::NativeTheme* theme) {
43 return NativeScrollBarWrapper::GetVerticalScrollBarWidth(theme);
46 ////////////////////////////////////////////////////////////////////////////////
47 // NativeScrollBar, View overrides:
48 gfx::Size NativeScrollBar::GetPreferredSize() {
50 return native_wrapper_->GetView()->GetPreferredSize();
54 void NativeScrollBar::Layout() {
55 if (native_wrapper_) {
56 native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
57 native_wrapper_->GetView()->Layout();
61 void NativeScrollBar::ViewHierarchyChanged(
62 const ViewHierarchyChangedDetails& details) {
64 if (details.is_add && !native_wrapper_ && (widget = GetWidget())) {
65 native_wrapper_ = NativeScrollBarWrapper::CreateWrapper(this);
66 AddChildView(native_wrapper_->GetView());
70 const char* NativeScrollBar::GetClassName() const {
71 return kViewClassName;
74 // Overridden from View for keyboard UI.
75 bool NativeScrollBar::OnKeyPressed(const ui::KeyEvent& event) {
78 return native_wrapper_->GetView()->OnKeyPressed(event);
81 void NativeScrollBar::OnGestureEvent(ui::GestureEvent* event) {
84 native_wrapper_->GetView()->OnGestureEvent(event);
87 bool NativeScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) {
90 return native_wrapper_->GetView()->OnMouseWheel(event);
93 ////////////////////////////////////////////////////////////////////////////////
94 // NativeScrollBar, ScrollBar overrides:
95 void NativeScrollBar::Update(int viewport_size,
98 ScrollBar::Update(viewport_size, content_size, current_pos);
101 native_wrapper_->Update(viewport_size, content_size, current_pos);
104 int NativeScrollBar::GetLayoutSize() const {
105 return IsHorizontal() ?
106 GetHorizontalScrollBarHeight(GetNativeTheme()) :
107 GetVerticalScrollBarWidth(GetNativeTheme());
110 int NativeScrollBar::GetPosition() const {
111 if (!native_wrapper_)
113 return native_wrapper_->GetPosition();