OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "views/controls/scrollbar/native_scroll_bar_wayland.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/base/keycodes/keyboard_codes_posix.h" |
| 9 #include "ui/wayland/wayland_widget.h" |
| 10 #include "views/controls/scrollbar/native_scroll_bar.h" |
| 11 #include "views/controls/scrollbar/scroll_bar.h" |
| 12 |
| 13 |
| 14 namespace views { |
| 15 |
| 16 //////////////////////////////////////////////////////////////////////////////// |
| 17 // NativeScrollBarWayland, public: |
| 18 |
| 19 NativeScrollBarWayland::NativeScrollBarWayland(NativeScrollBar* scroll_bar) |
| 20 : NativeControlWayland(), |
| 21 native_scroll_bar_(scroll_bar) { |
| 22 set_focus_view(scroll_bar); |
| 23 } |
| 24 |
| 25 NativeScrollBarWayland::~NativeScrollBarWayland() { |
| 26 } |
| 27 |
| 28 //////////////////////////////////////////////////////////////////////////////// |
| 29 // NativeScrollBarWayland, View overrides: |
| 30 |
| 31 void NativeScrollBarWayland::Layout() { |
| 32 SetBoundsRect(native_scroll_bar_->GetLocalBounds()); |
| 33 NativeControlWayland::Layout(); |
| 34 } |
| 35 |
| 36 gfx::Size NativeScrollBarWayland::GetPreferredSize() { |
| 37 if (native_scroll_bar_->IsHorizontal()) |
| 38 return gfx::Size(0, GetHorizontalScrollBarHeight()); |
| 39 return gfx::Size(GetVerticalScrollBarWidth(), 0); |
| 40 } |
| 41 |
| 42 // TODO(oshima|jcampan): key/mouse events are not delievered and |
| 43 // the following code is not tested. It requires the focus manager to be fully |
| 44 // implemented. |
| 45 bool NativeScrollBarWayland::OnKeyPressed(const KeyEvent& event) { |
| 46 if (!native_view()) |
| 47 return false; |
| 48 switch (event.key_code()) { |
| 49 case ui::VKEY_UP: |
| 50 if (!native_scroll_bar_->IsHorizontal()) |
| 51 MoveStep(false /* negative */); |
| 52 break; |
| 53 case ui::VKEY_DOWN: |
| 54 if (!native_scroll_bar_->IsHorizontal()) |
| 55 MoveStep(true /* positive */); |
| 56 break; |
| 57 case ui::VKEY_LEFT: |
| 58 if (native_scroll_bar_->IsHorizontal()) |
| 59 MoveStep(false /* negative */); |
| 60 break; |
| 61 case ui::VKEY_RIGHT: |
| 62 if (native_scroll_bar_->IsHorizontal()) |
| 63 MoveStep(true /* positive */); |
| 64 break; |
| 65 case ui::VKEY_PRIOR: |
| 66 MovePage(false /* negative */); |
| 67 break; |
| 68 case ui::VKEY_NEXT: |
| 69 MovePage(true /* positive */); |
| 70 break; |
| 71 case ui::VKEY_HOME: |
| 72 MoveTo(0); |
| 73 break; |
| 74 case ui::VKEY_END: |
| 75 MoveToBottom(); |
| 76 break; |
| 77 default: |
| 78 return false; |
| 79 } |
| 80 return true; |
| 81 } |
| 82 |
| 83 bool NativeScrollBarWayland::OnMouseWheel(const MouseWheelEvent& e) { |
| 84 if (!native_view()) |
| 85 return false; |
| 86 MoveBy(-e.offset()); // e.GetOffset() > 0 means scroll up. |
| 87 return true; |
| 88 } |
| 89 |
| 90 //////////////////////////////////////////////////////////////////////////////// |
| 91 // NativeScrollBarWayland, NativeControlWayland overrides: |
| 92 |
| 93 void NativeScrollBarWayland::CreateNativeControl() { |
| 94 NOTIMPLEMENTED(); |
| 95 } |
| 96 |
| 97 //////////////////////////////////////////////////////////////////////////////// |
| 98 // NativeScrollBarWayland, NativeScrollBarWrapper overrides: |
| 99 |
| 100 int NativeScrollBarWayland::GetPosition() const { |
| 101 NOTIMPLEMENTED(); |
| 102 return 0; |
| 103 } |
| 104 |
| 105 View* NativeScrollBarWayland::GetView() { |
| 106 return this; |
| 107 } |
| 108 |
| 109 void NativeScrollBarWayland::Update(int viewport_size, |
| 110 int content_size, |
| 111 int current_pos) { |
| 112 NOTIMPLEMENTED(); |
| 113 } |
| 114 |
| 115 //////////////////////////////////////////////////////////////////////////////// |
| 116 // NativeScrollBarWayland, private: |
| 117 |
| 118 void NativeScrollBarWayland::ValueChanged() { |
| 119 ScrollBarController* controller = native_scroll_bar_->GetController(); |
| 120 controller->ScrollToPosition(native_scroll_bar_, GetPosition()); |
| 121 } |
| 122 |
| 123 // static |
| 124 void NativeScrollBarWayland::CallValueChanged(ui::WaylandWidget* widget, |
| 125 NativeScrollBarWayland* scroll_bar) { |
| 126 scroll_bar->ValueChanged(); |
| 127 } |
| 128 |
| 129 void NativeScrollBarWayland::MoveBy(int o) { |
| 130 MoveTo(GetPosition() + o); |
| 131 } |
| 132 |
| 133 void NativeScrollBarWayland::MovePage(bool positive) { |
| 134 ScrollBarController* controller = native_scroll_bar_->GetController(); |
| 135 MoveBy(controller->GetScrollIncrement(native_scroll_bar_, true, positive)); |
| 136 } |
| 137 |
| 138 void NativeScrollBarWayland::MoveStep(bool positive) { |
| 139 ScrollBarController* controller = native_scroll_bar_->GetController(); |
| 140 MoveBy(controller->GetScrollIncrement(native_scroll_bar_, false, positive)); |
| 141 } |
| 142 |
| 143 void NativeScrollBarWayland::MoveTo(int p) { |
| 144 if (p < native_scroll_bar_->GetMinPosition()) |
| 145 p = native_scroll_bar_->GetMinPosition(); |
| 146 if (p > native_scroll_bar_->GetMaxPosition()) |
| 147 p = native_scroll_bar_->GetMaxPosition(); |
| 148 NOTIMPLEMENTED(); |
| 149 } |
| 150 |
| 151 void NativeScrollBarWayland::MoveToBottom() { |
| 152 NOTIMPLEMENTED(); |
| 153 } |
| 154 |
| 155 //////////////////////////////////////////////////////////////////////////////// |
| 156 // NativewScrollBarWrapper, public: |
| 157 |
| 158 // static |
| 159 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper( |
| 160 NativeScrollBar* scroll_bar) { |
| 161 return new NativeScrollBarWayland(scroll_bar); |
| 162 } |
| 163 |
| 164 // static |
| 165 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() { |
| 166 return 20; |
| 167 } |
| 168 |
| 169 // static |
| 170 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() { |
| 171 return 20; |
| 172 } |
| 173 |
| 174 } // namespace views |
OLD | NEW |