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

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

Powered by Google App Engine
This is Rietveld 408576698