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

Side by Side Diff: ui/aura/window_tree_host_platform.cc

Issue 1390883003: aura: Unify WindowTreeHost for some platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ash_unittests, sadrul's comments Created 5 years, 2 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
(Empty)
1 // Copyright 2015 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/aura/window_tree_host_platform.h"
6
7 #include <algorithm>
dnicoara 2015/10/16 18:30:57 And this include can probably go to.
no sievers 2015/10/16 18:42:24 Done.
8
9 #include "base/trace_event/trace_event.h"
10 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/compositor/compositor.h"
12 #include "ui/events/event.h"
13 #include "ui/gfx/screen.h"
14
15 #if defined(OS_ANDROID)
16 #include "ui/platform_window/android/platform_window_android.h"
17 #endif
18
19 #if defined(USE_OZONE)
20 #include "ui/ozone/public/ozone_platform.h"
21 #endif
22
23 #if defined(OS_WIN)
24 #include "base/message_loop/message_loop.h"
25 #include "ui/platform_window/win/win_window.h"
26 #endif
27
28 using std::max;
dnicoara 2015/10/16 18:30:57 These don't seem to be used.
no sievers 2015/10/16 18:42:24 Done.
no sievers 2015/10/16 18:42:24 Done.
29 using std::min;
30
31 namespace aura {
32
33 // static
34 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
35 return new WindowTreeHostPlatform(bounds);
36 }
37
38 WindowTreeHostPlatform::WindowTreeHostPlatform(const gfx::Rect& bounds)
39 : widget_(gfx::kNullAcceleratedWidget),
40 current_cursor_(ui::kCursorNull),
41 has_capture_(false) {
42 #if defined(USE_OZONE)
43 window_ =
44 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds);
45 #elif defined(OS_WIN)
46 window_.reset(new ui::WinWindow(this, bounds));
47 #elif defined(OS_ANDROID)
48 window_.reset(new ui::PlatformWindowAndroid(this));
49 #else
50 NOTIMPLEMENTED();
51 #endif
52 }
53
54 WindowTreeHostPlatform::~WindowTreeHostPlatform() {
55 DestroyCompositor();
56 DestroyDispatcher();
57 }
58
59 ui::EventSource* WindowTreeHostPlatform::GetEventSource() {
60 return this;
61 }
62
63 gfx::AcceleratedWidget WindowTreeHostPlatform::GetAcceleratedWidget() {
64 return widget_;
65 }
66
67 void WindowTreeHostPlatform::ShowImpl() {
68 window_->Show();
69 }
70
71 void WindowTreeHostPlatform::HideImpl() {
72 window_->Hide();
73 }
74
75 gfx::Rect WindowTreeHostPlatform::GetBounds() const {
76 return window_->GetBounds();
77 }
78
79 void WindowTreeHostPlatform::SetBounds(const gfx::Rect& bounds) {
80 window_->SetBounds(bounds);
81 }
82
83 gfx::Point WindowTreeHostPlatform::GetLocationOnNativeScreen() const {
84 return window_->GetBounds().origin();
85 }
86
87 void WindowTreeHostPlatform::SetCapture() {
88 if (!has_capture_) {
89 has_capture_ = true;
90 window_->SetCapture();
91 }
92 }
93
94 void WindowTreeHostPlatform::ReleaseCapture() {
95 if (has_capture_)
96 window_->ReleaseCapture();
97 }
98
99 void WindowTreeHostPlatform::SetCursorNative(gfx::NativeCursor cursor) {
100 if (cursor == current_cursor_)
101 return;
102 current_cursor_ = cursor;
103
104 window_->SetCursor(cursor.platform());
105 }
106
107 void WindowTreeHostPlatform::MoveCursorToNative(const gfx::Point& location) {
108 window_->MoveCursorTo(location);
109 }
110
111 void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) {
112 NOTIMPLEMENTED();
113 }
114
115 void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) {
116 float current_scale = compositor()->device_scale_factor();
117 float new_scale = gfx::Screen::GetScreenFor(window())
118 ->GetDisplayNearestWindow(window())
119 .device_scale_factor();
120 gfx::Rect old_bounds = bounds_;
121 bounds_ = new_bounds;
122 if (bounds_.origin() != old_bounds.origin()) {
123 OnHostMoved(bounds_.origin());
124 }
125 if (bounds_.size() != old_bounds.size() || current_scale != new_scale) {
126 OnHostResized(bounds_.size());
127 }
128 }
129
130 void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) {
131 compositor()->ScheduleRedrawRect(damage_rect);
132 }
133
134 void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) {
135 TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent");
136 ui::EventDispatchDetails details = SendEventToProcessor(event);
137 if (details.dispatcher_destroyed)
138 event->SetHandled();
139 }
140
141 void WindowTreeHostPlatform::OnCloseRequest() {
142 #if defined(OS_WIN)
143 // TODO: this obviously shouldn't be here.
144 base::MessageLoopForUI::current()->QuitWhenIdle();
145 #else
146 OnHostCloseRequested();
147 #endif
148 }
149
150 void WindowTreeHostPlatform::OnClosed() {}
151
152 void WindowTreeHostPlatform::OnWindowStateChanged(
153 ui::PlatformWindowState new_state) {}
154
155 void WindowTreeHostPlatform::OnLostCapture() {
156 if (has_capture_) {
157 has_capture_ = false;
158 OnHostLostWindowCapture();
159 }
160 }
161
162 void WindowTreeHostPlatform::OnAcceleratedWidgetAvailable(
163 gfx::AcceleratedWidget widget,
164 float device_pixel_ratio) {
165 widget_ = widget;
166 CreateCompositor();
167 WindowTreeHost::OnAcceleratedWidgetAvailable();
168 }
169
170 void WindowTreeHostPlatform::OnActivationChanged(bool active) {
171 if (active)
172 OnHostActivated();
173 }
174
175 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698