| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <string> | |
| 9 | |
| 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" | |
| 15 | |
| 16 namespace views { | |
| 17 | |
| 18 // static | |
| 19 const char NativeScrollBar::kViewClassName[] = "NativeScrollBar"; | |
| 20 | |
| 21 //////////////////////////////////////////////////////////////////////////////// | |
| 22 // NativeScrollBar, public: | |
| 23 NativeScrollBar::NativeScrollBar(bool is_horizontal) | |
| 24 : ScrollBar(is_horizontal), | |
| 25 native_wrapper_(NULL) { | |
| 26 } | |
| 27 | |
| 28 NativeScrollBar::~NativeScrollBar() { | |
| 29 } | |
| 30 | |
| 31 // static | |
| 32 int NativeScrollBar::GetHorizontalScrollBarHeight( | |
| 33 const ui::NativeTheme* theme) { | |
| 34 return NativeScrollBarWrapper::GetHorizontalScrollBarHeight(theme); | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 int NativeScrollBar::GetVerticalScrollBarWidth( | |
| 39 const ui::NativeTheme* theme) { | |
| 40 return NativeScrollBarWrapper::GetVerticalScrollBarWidth(theme); | |
| 41 } | |
| 42 | |
| 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(); | |
| 49 } | |
| 50 | |
| 51 void NativeScrollBar::Layout() { | |
| 52 if (native_wrapper_) { | |
| 53 native_wrapper_->GetView()->SetBounds(0, 0, width(), height()); | |
| 54 native_wrapper_->GetView()->Layout(); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 void NativeScrollBar::ViewHierarchyChanged( | |
| 59 const ViewHierarchyChangedDetails& details) { | |
| 60 if (details.is_add && !native_wrapper_ && GetWidget()) { | |
| 61 native_wrapper_ = NativeScrollBarWrapper::CreateWrapper(this); | |
| 62 AddChildView(native_wrapper_->GetView()); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 const char* NativeScrollBar::GetClassName() const { | |
| 67 return kViewClassName; | |
| 68 } | |
| 69 | |
| 70 // Overridden from View for keyboard UI. | |
| 71 bool NativeScrollBar::OnKeyPressed(const ui::KeyEvent& event) { | |
| 72 if (!native_wrapper_) | |
| 73 return false; | |
| 74 return native_wrapper_->GetView()->OnKeyPressed(event); | |
| 75 } | |
| 76 | |
| 77 void NativeScrollBar::OnGestureEvent(ui::GestureEvent* event) { | |
| 78 if (!native_wrapper_) | |
| 79 return; | |
| 80 native_wrapper_->GetView()->OnGestureEvent(event); | |
| 81 } | |
| 82 | |
| 83 bool NativeScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) { | |
| 84 if (!native_wrapper_) | |
| 85 return false; | |
| 86 return native_wrapper_->GetView()->OnMouseWheel(event); | |
| 87 } | |
| 88 | |
| 89 //////////////////////////////////////////////////////////////////////////////// | |
| 90 // NativeScrollBar, ScrollBar overrides: | |
| 91 void NativeScrollBar::Update(int viewport_size, | |
| 92 int content_size, | |
| 93 int current_pos) { | |
| 94 ScrollBar::Update(viewport_size, content_size, current_pos); | |
| 95 | |
| 96 if (native_wrapper_) | |
| 97 native_wrapper_->Update(viewport_size, content_size, current_pos); | |
| 98 } | |
| 99 | |
| 100 int NativeScrollBar::GetLayoutSize() const { | |
| 101 return IsHorizontal() ? | |
| 102 GetHorizontalScrollBarHeight(GetNativeTheme()) : | |
| 103 GetVerticalScrollBarWidth(GetNativeTheme()); | |
| 104 } | |
| 105 | |
| 106 int NativeScrollBar::GetPosition() const { | |
| 107 if (!native_wrapper_) | |
| 108 return 0; | |
| 109 return native_wrapper_->GetPosition(); | |
| 110 } | |
| 111 | |
| 112 } // namespace views | |
| 113 | |
| OLD | NEW |