Chromium Code Reviews| Index: views/controls/scrollbar/native_scroll_bar_wayland.cc |
| diff --git a/views/controls/scrollbar/native_scroll_bar_wayland.cc b/views/controls/scrollbar/native_scroll_bar_wayland.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f069223ea1f560f7816cad4db8fe812518dc63a |
| --- /dev/null |
| +++ b/views/controls/scrollbar/native_scroll_bar_wayland.cc |
| @@ -0,0 +1,174 @@ |
| +// Copyright (c) 2011 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_wayland.h" |
| + |
| +#include "base/logging.h" |
| +#include "ui/base/keycodes/keyboard_codes_posix.h" |
| +#include "ui/wayland/wayland_widget.h" |
|
sadrul
2011/08/15 14:50:23
How much wayland-only code is in here? It looks li
|
| +#include "views/controls/scrollbar/native_scroll_bar.h" |
| +#include "views/controls/scrollbar/scroll_bar.h" |
| + |
| + |
| +namespace views { |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// NativeScrollBarWayland, public: |
| + |
| +NativeScrollBarWayland::NativeScrollBarWayland(NativeScrollBar* scroll_bar) |
| + : NativeControlWayland(), |
| + native_scroll_bar_(scroll_bar) { |
| + set_focus_view(scroll_bar); |
| +} |
| + |
| +NativeScrollBarWayland::~NativeScrollBarWayland() { |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// NativeScrollBarWayland, View overrides: |
| + |
| +void NativeScrollBarWayland::Layout() { |
| + SetBoundsRect(native_scroll_bar_->GetLocalBounds()); |
| + NativeControlWayland::Layout(); |
| +} |
| + |
| +gfx::Size NativeScrollBarWayland::GetPreferredSize() { |
| + if (native_scroll_bar_->IsHorizontal()) |
| + return gfx::Size(0, GetHorizontalScrollBarHeight()); |
| + return gfx::Size(GetVerticalScrollBarWidth(), 0); |
| +} |
| + |
| +// TODO(oshima|jcampan): key/mouse events are not delievered and |
| +// the following code is not tested. It requires the focus manager to be fully |
| +// implemented. |
| +bool NativeScrollBarWayland::OnKeyPressed(const KeyEvent& event) { |
| + if (!native_view()) |
| + return false; |
| + switch (event.key_code()) { |
| + case ui::VKEY_UP: |
| + if (!native_scroll_bar_->IsHorizontal()) |
| + MoveStep(false /* negative */); |
| + break; |
| + case ui::VKEY_DOWN: |
| + if (!native_scroll_bar_->IsHorizontal()) |
| + MoveStep(true /* positive */); |
| + break; |
| + case ui::VKEY_LEFT: |
| + if (native_scroll_bar_->IsHorizontal()) |
| + MoveStep(false /* negative */); |
| + break; |
| + case ui::VKEY_RIGHT: |
| + if (native_scroll_bar_->IsHorizontal()) |
| + MoveStep(true /* positive */); |
| + break; |
| + case ui::VKEY_PRIOR: |
| + MovePage(false /* negative */); |
| + break; |
| + case ui::VKEY_NEXT: |
| + MovePage(true /* positive */); |
| + break; |
| + case ui::VKEY_HOME: |
| + MoveTo(0); |
| + break; |
| + case ui::VKEY_END: |
| + MoveToBottom(); |
| + break; |
| + default: |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +bool NativeScrollBarWayland::OnMouseWheel(const MouseWheelEvent& e) { |
| + if (!native_view()) |
| + return false; |
| + MoveBy(-e.offset()); // e.GetOffset() > 0 means scroll up. |
| + return true; |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// NativeScrollBarWayland, NativeControlWayland overrides: |
| + |
| +void NativeScrollBarWayland::CreateNativeControl() { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// NativeScrollBarWayland, NativeScrollBarWrapper overrides: |
| + |
| +int NativeScrollBarWayland::GetPosition() const { |
| + NOTIMPLEMENTED(); |
| + return 0; |
| +} |
| + |
| +View* NativeScrollBarWayland::GetView() { |
| + return this; |
| +} |
| + |
| +void NativeScrollBarWayland::Update(int viewport_size, |
| + int content_size, |
|
sadrul
2011/08/15 14:50:23
Indentation (here and other places).
|
| + int current_pos) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// NativeScrollBarWayland, private: |
| + |
| +void NativeScrollBarWayland::ValueChanged() { |
| + ScrollBarController* controller = native_scroll_bar_->GetController(); |
| + controller->ScrollToPosition(native_scroll_bar_, GetPosition()); |
| +} |
| + |
| +// static |
| +void NativeScrollBarWayland::CallValueChanged(ui::WaylandWidget* widget, |
| + NativeScrollBarWayland* scroll_bar) { |
| + scroll_bar->ValueChanged(); |
| +} |
| + |
| +void NativeScrollBarWayland::MoveBy(int o) { |
| + MoveTo(GetPosition() + o); |
| +} |
| + |
| +void NativeScrollBarWayland::MovePage(bool positive) { |
| + ScrollBarController* controller = native_scroll_bar_->GetController(); |
| + MoveBy(controller->GetScrollIncrement(native_scroll_bar_, true, positive)); |
| +} |
| + |
| +void NativeScrollBarWayland::MoveStep(bool positive) { |
| + ScrollBarController* controller = native_scroll_bar_->GetController(); |
| + MoveBy(controller->GetScrollIncrement(native_scroll_bar_, false, positive)); |
| +} |
| + |
| +void NativeScrollBarWayland::MoveTo(int p) { |
| + if (p < native_scroll_bar_->GetMinPosition()) |
| + p = native_scroll_bar_->GetMinPosition(); |
| + if (p > native_scroll_bar_->GetMaxPosition()) |
| + p = native_scroll_bar_->GetMaxPosition(); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void NativeScrollBarWayland::MoveToBottom() { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// NativewScrollBarWrapper, public: |
| + |
| +// static |
| +NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper( |
| + NativeScrollBar* scroll_bar) { |
| + return new NativeScrollBarWayland(scroll_bar); |
| +} |
| + |
| +// static |
| +int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() { |
| + return 20; |
| +} |
| + |
| +// static |
| +int NativeScrollBarWrapper::GetVerticalScrollBarWidth() { |
| + return 20; |
| +} |
| + |
| +} // namespace views |