Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: components/view_manager/native_viewport/platform_viewport_common.cc

Issue 1180573004: android: Introduce a ui::PlatformWindow implementation for android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix-win-gn Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/view_manager/native_viewport/platform_viewport.h" 5 #include "components/view_manager/native_viewport/platform_viewport.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "components/view_manager/native_viewport/platform_viewport_headless.h" 9 #include "components/view_manager/native_viewport/platform_viewport_headless.h"
10 #include "components/view_manager/public/interfaces/view_manager.mojom.h" 10 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h" 11 #include "mojo/converters/geometry/geometry_type_converters.h"
12 #include "mojo/converters/input_events/input_events_type_converters.h" 12 #include "mojo/converters/input_events/input_events_type_converters.h"
13 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" 13 #include "mojo/converters/input_events/mojo_extended_key_event_data.h"
14 #include "ui/events/event.h" 14 #include "ui/events/event.h"
15 #include "ui/events/event_utils.h" 15 #include "ui/events/event_utils.h"
16 #include "ui/events/platform/platform_event_dispatcher.h" 16 #include "ui/events/platform/platform_event_dispatcher.h"
17 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/platform_window/platform_window.h" 18 #include "ui/platform_window/platform_window.h"
19 #include "ui/platform_window/platform_window_delegate.h" 19 #include "ui/platform_window/platform_window_delegate.h"
20
21 #if defined(OS_WIN)
22 #include "ui/platform_window/win/win_window.h"
23 #elif defined(USE_X11)
20 #include "ui/platform_window/x11/x11_window.h" 24 #include "ui/platform_window/x11/x11_window.h"
25 #elif defined(OS_ANDROID)
26 #include "ui/platform_window/android/platform_window_android.h"
27 #endif
21 28
22 namespace native_viewport { 29 namespace native_viewport {
23 namespace { 30 namespace {
24 31
25 float ConvertUIWheelValueToMojoValue(int offset) { 32 float ConvertUIWheelValueToMojoValue(int offset) {
26 // Mojo's event type takes a value between -1 and 1. Normalize by allowing 33 // Mojo's event type takes a value between -1 and 1. Normalize by allowing
27 // up to 20 of ui's offset. This is a bit arbitrary. 34 // up to 20 of ui's offset. This is a bit arbitrary.
28 return std::max( 35 return std::max(
29 -1.0f, std::min(1.0f, static_cast<float>(offset) / 36 -1.0f, std::min(1.0f, static_cast<float>(offset) /
30 (20 * static_cast<float>( 37 (20 * static_cast<float>(
31 ui::MouseWheelEvent::kWheelDelta)))); 38 ui::MouseWheelEvent::kWheelDelta))));
32 } 39 }
33 } // namespace 40 } // namespace
34 41
35 class PlatformViewportX11 : public PlatformViewport, 42 class PlatformViewportCommon : public PlatformViewport,
36 public ui::PlatformWindowDelegate { 43 public ui::PlatformWindowDelegate {
37 public: 44 public:
38 explicit PlatformViewportX11(Delegate* delegate) : delegate_(delegate) { 45 explicit PlatformViewportCommon(Delegate* delegate) : delegate_(delegate) {
39 } 46 }
40 47
41 ~PlatformViewportX11() override { 48 ~PlatformViewportCommon() override {
42 // Destroy the platform-window while |this| is still alive. 49 // Destroy the platform-window while |this| is still alive.
43 platform_window_.reset(); 50 platform_window_.reset();
44 } 51 }
45 52
46 private: 53 private:
47 // Overridden from PlatformViewport: 54 // Overridden from PlatformViewport:
48 void Init(const gfx::Rect& bounds) override { 55 void Init(const gfx::Rect& bounds) override {
49 CHECK(!platform_window_); 56 CHECK(!platform_window_);
50 57
51 metrics_ = mojo::ViewportMetrics::New(); 58 metrics_ = mojo::ViewportMetrics::New();
52 // TODO(sky): make density real. 59 // TODO(sky): make density real.
53 metrics_->device_pixel_ratio = 1.f; 60 metrics_->device_pixel_ratio = 1.f;
54 metrics_->size_in_pixels = mojo::Size::From(bounds.size()); 61 metrics_->size_in_pixels = mojo::Size::From(bounds.size());
55 62
63 #if defined(OS_WIN)
64 platform_window_.reset(new ui::WinWindow(this, bounds));
65 #elif defined(USE_X11)
56 platform_window_.reset(new ui::X11Window(this)); 66 platform_window_.reset(new ui::X11Window(this));
67 #elif defined(OS_ANDROID)
68 platform_window_.reset(new ui::PlatformWindowAndroid(this));
69 #endif
57 platform_window_->SetBounds(bounds); 70 platform_window_->SetBounds(bounds);
58 } 71 }
59 72
60 void Show() override { platform_window_->Show(); } 73 void Show() override { platform_window_->Show(); }
61 74
62 void Hide() override { platform_window_->Hide(); } 75 void Hide() override { platform_window_->Hide(); }
63 76
64 void Close() override { platform_window_->Close(); } 77 void Close() override { platform_window_->Close(); }
65 78
66 gfx::Size GetSize() override { 79 gfx::Size GetSize() override {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 platform_window_->SetCapture(); 114 platform_window_->SetCapture();
102 break; 115 break;
103 case ui::ET_MOUSE_RELEASED: 116 case ui::ET_MOUSE_RELEASED:
104 case ui::ET_TOUCH_RELEASED: 117 case ui::ET_TOUCH_RELEASED:
105 platform_window_->ReleaseCapture(); 118 platform_window_->ReleaseCapture();
106 break; 119 break;
107 default: 120 default:
108 break; 121 break;
109 } 122 }
110 123
124 #if defined(USE_X11)
111 // We want to emulate the WM_CHAR generation behaviour of Windows. 125 // We want to emulate the WM_CHAR generation behaviour of Windows.
112 // 126 //
113 // On Linux, we've previously inserted characters by having 127 // On Linux, we've previously inserted characters by having
114 // InputMethodAuraLinux take all key down events and send a character event 128 // InputMethodAuraLinux take all key down events and send a character event
115 // to the TextInputClient. This causes a mismatch in code that has to be 129 // to the TextInputClient. This causes a mismatch in code that has to be
116 // shared between Windows and Linux, including blink code. Now that we're 130 // shared between Windows and Linux, including blink code. Now that we're
117 // trying to have one way of doing things, we need to standardize on and 131 // trying to have one way of doing things, we need to standardize on and
118 // emulate Windows character events. 132 // emulate Windows character events.
119 // 133 //
120 // This is equivalent to what we're doing in the current Linux port, but 134 // This is equivalent to what we're doing in the current Linux port, but
(...skipping 10 matching lines...) Expand all
131 145
132 char_event.SetExtendedKeyEventData( 146 char_event.SetExtendedKeyEventData(
133 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( 147 make_scoped_ptr(new mojo::MojoExtendedKeyEventData(
134 key_press_event->GetLocatedWindowsKeyboardCode(), 148 key_press_event->GetLocatedWindowsKeyboardCode(),
135 key_press_event->GetText(), 149 key_press_event->GetText(),
136 key_press_event->GetUnmodifiedText()))); 150 key_press_event->GetUnmodifiedText())));
137 char_event.set_platform_keycode(key_press_event->platform_keycode()); 151 char_event.set_platform_keycode(key_press_event->platform_keycode());
138 152
139 delegate_->OnEvent(mojo::Event::From(char_event)); 153 delegate_->OnEvent(mojo::Event::From(char_event));
140 } 154 }
155 #endif
141 } 156 }
142 157
143 void OnCloseRequest() override { platform_window_->Close(); } 158 void OnCloseRequest() override { platform_window_->Close(); }
144 159
145 void OnClosed() override { delegate_->OnDestroyed(); } 160 void OnClosed() override { delegate_->OnDestroyed(); }
146 161
147 void OnWindowStateChanged(ui::PlatformWindowState state) override {} 162 void OnWindowStateChanged(ui::PlatformWindowState state) override {}
148 163
149 void OnLostCapture() override {} 164 void OnLostCapture() override {}
150 165
151 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override { 166 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
152 delegate_->OnAcceleratedWidgetAvailable(widget, 167 delegate_->OnAcceleratedWidgetAvailable(widget,
153 metrics_->device_pixel_ratio); 168 metrics_->device_pixel_ratio);
154 } 169 }
155 170
156 void OnActivationChanged(bool active) override {} 171 void OnActivationChanged(bool active) override {}
157 172
158 scoped_ptr<ui::PlatformWindow> platform_window_; 173 scoped_ptr<ui::PlatformWindow> platform_window_;
159 Delegate* delegate_; 174 Delegate* delegate_;
160 mojo::ViewportMetricsPtr metrics_; 175 mojo::ViewportMetricsPtr metrics_;
161 176
162 DISALLOW_COPY_AND_ASSIGN(PlatformViewportX11); 177 DISALLOW_COPY_AND_ASSIGN(PlatformViewportCommon);
163 }; 178 };
164 179
165 // static 180 // static
166 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate, 181 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate,
167 bool headless) { 182 bool headless) {
168 if (headless) 183 if (headless)
169 return PlatformViewportHeadless::Create(delegate); 184 return PlatformViewportHeadless::Create(delegate);
170 return make_scoped_ptr(new PlatformViewportX11(delegate)); 185 return make_scoped_ptr(new PlatformViewportCommon(delegate));
171 } 186 }
172 187
173 } // namespace native_viewport 188 } // namespace native_viewport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698