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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc

Issue 1624793002: Make File-Picker modal on Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a WeakPtrFactory Created 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
6 6
7 #include <X11/extensions/shape.h> 7 #include <X11/extensions/shape.h>
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 #include <X11/Xregion.h> 10 #include <X11/Xregion.h>
(...skipping 21 matching lines...) Expand all
32 #include "ui/base/ime/input_method.h" 32 #include "ui/base/ime/input_method.h"
33 #include "ui/base/x/x11_util.h" 33 #include "ui/base/x/x11_util.h"
34 #include "ui/base/x/x11_util_internal.h" 34 #include "ui/base/x/x11_util_internal.h"
35 #include "ui/base/x/x11_window_event_manager.h" 35 #include "ui/base/x/x11_window_event_manager.h"
36 #include "ui/display/display.h" 36 #include "ui/display/display.h"
37 #include "ui/display/screen.h" 37 #include "ui/display/screen.h"
38 #include "ui/events/devices/x11/device_data_manager_x11.h" 38 #include "ui/events/devices/x11/device_data_manager_x11.h"
39 #include "ui/events/devices/x11/device_list_cache_x11.h" 39 #include "ui/events/devices/x11/device_list_cache_x11.h"
40 #include "ui/events/devices/x11/touch_factory_x11.h" 40 #include "ui/events/devices/x11/touch_factory_x11.h"
41 #include "ui/events/event_utils.h" 41 #include "ui/events/event_utils.h"
42 #include "ui/events/null_event_targeter.h"
42 #include "ui/events/platform/platform_event_source.h" 43 #include "ui/events/platform/platform_event_source.h"
43 #include "ui/events/platform/x11/x11_event_source.h" 44 #include "ui/events/platform/x11/x11_event_source.h"
44 #include "ui/gfx/geometry/insets.h" 45 #include "ui/gfx/geometry/insets.h"
45 #include "ui/gfx/geometry/size_conversions.h" 46 #include "ui/gfx/geometry/size_conversions.h"
46 #include "ui/gfx/image/image_skia.h" 47 #include "ui/gfx/image/image_skia.h"
47 #include "ui/gfx/image/image_skia_rep.h" 48 #include "ui/gfx/image/image_skia_rep.h"
48 #include "ui/gfx/path.h" 49 #include "ui/gfx/path.h"
49 #include "ui/gfx/path_x11.h" 50 #include "ui/gfx/path_x11.h"
50 #include "ui/native_theme/native_theme.h" 51 #include "ui/native_theme/native_theme.h"
51 #include "ui/native_theme/native_theme_aura.h" 52 #include "ui/native_theme/native_theme_aura.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 case XINotifyWhileGrabbed: 171 case XINotifyWhileGrabbed:
171 return NotifyWhileGrabbed; 172 return NotifyWhileGrabbed;
172 default: 173 default:
173 NOTREACHED(); 174 NOTREACHED();
174 return NotifyNormal; 175 return NotifyNormal;
175 } 176 }
176 } 177 }
177 178
178 } // namespace 179 } // namespace
179 180
181 DesktopWindowTreeHostX11::ScopedHandle::ScopedHandle(const base::Closure&
182 destroy_callback)
183 : destroy_callback_(destroy_callback) {
184 }
185
186 DesktopWindowTreeHostX11::ScopedHandle::~ScopedHandle() {
187 if (!destroy_callback_.is_null())
188 destroy_callback_.Run();
189 }
190
180 //////////////////////////////////////////////////////////////////////////////// 191 ////////////////////////////////////////////////////////////////////////////////
181 // DesktopWindowTreeHostX11, public: 192 // DesktopWindowTreeHostX11, public:
182 193
183 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( 194 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
184 internal::NativeWidgetDelegate* native_widget_delegate, 195 internal::NativeWidgetDelegate* native_widget_delegate,
185 DesktopNativeWidgetAura* desktop_native_widget_aura) 196 DesktopNativeWidgetAura* desktop_native_widget_aura)
186 : xdisplay_(gfx::GetXDisplay()), 197 : xdisplay_(gfx::GetXDisplay()),
187 xwindow_(0), 198 xwindow_(0),
188 x_root_window_(DefaultRootWindow(xdisplay_)), 199 x_root_window_(DefaultRootWindow(xdisplay_)),
189 atom_cache_(xdisplay_, kAtomsToCache), 200 atom_cache_(xdisplay_, kAtomsToCache),
190 window_mapped_(false), 201 window_mapped_(false),
191 wait_for_unmap_(false), 202 wait_for_unmap_(false),
192 is_fullscreen_(false), 203 is_fullscreen_(false),
193 is_always_on_top_(false), 204 is_always_on_top_(false),
194 use_native_frame_(false), 205 use_native_frame_(false),
195 should_maximize_after_map_(false), 206 should_maximize_after_map_(false),
196 use_argb_visual_(false), 207 use_argb_visual_(false),
197 drag_drop_client_(NULL), 208 drag_drop_client_(NULL),
198 native_widget_delegate_(native_widget_delegate), 209 native_widget_delegate_(native_widget_delegate),
199 desktop_native_widget_aura_(desktop_native_widget_aura), 210 desktop_native_widget_aura_(desktop_native_widget_aura),
200 content_window_(NULL), 211 content_window_(NULL),
201 window_parent_(NULL), 212 window_parent_(NULL),
202 custom_window_shape_(false), 213 custom_window_shape_(false),
203 urgency_hint_set_(false), 214 urgency_hint_set_(false),
204 has_pointer_grab_(false), 215 has_pointer_grab_(false),
205 activatable_(true), 216 activatable_(true),
206 has_pointer_(false), 217 has_pointer_(false),
207 has_window_focus_(false), 218 has_window_focus_(false),
208 has_pointer_focus_(false), 219 has_pointer_focus_(false),
209 close_widget_factory_(this) {} 220 modal_dialog_xid_(0),
221 scoped_handle_(NULL),
222 close_widget_factory_(this),
223 weak_factory_(this) {}
210 224
211 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { 225 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() {
212 window()->ClearProperty(kHostForRootWindow); 226 window()->ClearProperty(kHostForRootWindow);
213 aura::client::SetWindowMoveClient(window(), NULL); 227 aura::client::SetWindowMoveClient(window(), NULL);
214 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); 228 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
215 DestroyDispatcher(); 229 DestroyDispatcher();
216 } 230 }
217 231
218 // static 232 // static
219 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { 233 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) {
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 if (g_current_capture && g_current_capture != this && 1781 if (g_current_capture && g_current_capture != this &&
1768 event->type() == ui::ET_TOUCH_PRESSED) { 1782 event->type() == ui::ET_TOUCH_PRESSED) {
1769 ConvertEventToDifferentHost(event, g_current_capture); 1783 ConvertEventToDifferentHost(event, g_current_capture);
1770 g_current_capture->SendEventToProcessor(event); 1784 g_current_capture->SendEventToProcessor(event);
1771 } else { 1785 } else {
1772 SendEventToProcessor(event); 1786 SendEventToProcessor(event);
1773 } 1787 }
1774 } 1788 }
1775 1789
1776 void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) { 1790 void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) {
1777 GetInputMethod()->DispatchKeyEvent(event); 1791 if (native_widget_delegate_->AsWidget()->IsActive())
1792 GetInputMethod()->DispatchKeyEvent(event);
1778 } 1793 }
1779 1794
1780 void DesktopWindowTreeHostX11::ConvertEventToDifferentHost( 1795 void DesktopWindowTreeHostX11::ConvertEventToDifferentHost(
1781 ui::LocatedEvent* located_event, 1796 ui::LocatedEvent* located_event,
1782 DesktopWindowTreeHostX11* host) { 1797 DesktopWindowTreeHostX11* host) {
1783 DCHECK_NE(this, host); 1798 DCHECK_NE(this, host);
1784 const display::Display display_src = 1799 const display::Display display_src =
1785 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); 1800 display::Screen::GetScreen()->GetDisplayNearestWindow(window());
1786 const display::Display display_dest = 1801 const display::Display display_dest =
1787 display::Screen::GetScreen()->GetDisplayNearestWindow(host->window()); 1802 display::Screen::GetScreen()->GetDisplayNearestWindow(host->window());
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2289 return gfx::ToEnclosingRect(rect_in_dip); 2304 return gfx::ToEnclosingRect(rect_in_dip);
2290 } 2305 }
2291 2306
2292 gfx::Rect DesktopWindowTreeHostX11::ToPixelRect( 2307 gfx::Rect DesktopWindowTreeHostX11::ToPixelRect(
2293 const gfx::Rect& rect_in_dip) const { 2308 const gfx::Rect& rect_in_dip) const {
2294 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip); 2309 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip);
2295 GetRootTransform().TransformRect(&rect_in_pixels); 2310 GetRootTransform().TransformRect(&rect_in_pixels);
2296 return gfx::ToEnclosingRect(rect_in_pixels); 2311 return gfx::ToEnclosingRect(rect_in_pixels);
2297 } 2312 }
2298 2313
2314 XID DesktopWindowTreeHostX11::GetModalDialog() {
2315 return modal_dialog_xid_;
2316 }
2317
2318 std::unique_ptr<DesktopWindowTreeHostX11::ScopedHandle>
2319 DesktopWindowTreeHostX11::DisableEventListening(XID dialog) {
2320 DCHECK(dialog);
2321 DCHECK(!modal_dialog_xid_);
2322 modal_dialog_xid_ = dialog;
2323 // ScopedWindowTargeter is used to temporarily replace the event-targeter
2324 // with NullEventTargeter to make |dialog| modal.
2325 targeter_for_modal_.reset(new aura::ScopedWindowTargeter(window(),
2326 std::unique_ptr<ui::EventTargeter>(new ui::NullEventTargeter)));
2327
2328 scoped_handle_ = new DesktopWindowTreeHostX11::ScopedHandle(
2329 base::Bind(&DesktopWindowTreeHostX11::EnableEventListening,
2330 weak_factory_.GetWeakPtr()));
2331 return base::WrapUnique(scoped_handle_);
sadrul 2016/09/30 12:22:27 return base::MakeUnique<...>(base::Bind...)
joone 2016/10/01 00:03:16 Done.
2332 }
2333
2334 void DesktopWindowTreeHostX11::EnableEventListening() {
2335 DCHECK(modal_dialog_xid_);
2336 modal_dialog_xid_ = 0;
2337 targeter_for_modal_.reset();
2338 }
2339
2299 //////////////////////////////////////////////////////////////////////////////// 2340 ////////////////////////////////////////////////////////////////////////////////
2300 // DesktopWindowTreeHost, public: 2341 // DesktopWindowTreeHost, public:
2301 2342
2302 // static 2343 // static
2303 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( 2344 DesktopWindowTreeHost* DesktopWindowTreeHost::Create(
2304 internal::NativeWidgetDelegate* native_widget_delegate, 2345 internal::NativeWidgetDelegate* native_widget_delegate,
2305 DesktopNativeWidgetAura* desktop_native_widget_aura) { 2346 DesktopNativeWidgetAura* desktop_native_widget_aura) {
2306 return new DesktopWindowTreeHostX11(native_widget_delegate, 2347 return new DesktopWindowTreeHostX11(native_widget_delegate,
2307 desktop_native_widget_aura); 2348 desktop_native_widget_aura);
2308 } 2349 }
2309 2350
2310 // static 2351 // static
2311 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { 2352 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) {
2312 const LinuxUI* linux_ui = LinuxUI::instance(); 2353 const LinuxUI* linux_ui = LinuxUI::instance();
2313 if (linux_ui) { 2354 if (linux_ui) {
2314 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); 2355 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window);
2315 if (native_theme) 2356 if (native_theme)
2316 return native_theme; 2357 return native_theme;
2317 } 2358 }
2318 2359
2319 return ui::NativeThemeAura::instance(); 2360 return ui::NativeThemeAura::instance();
2320 } 2361 }
2321 2362
2322 } // namespace views 2363 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698