OLD | NEW |
---|---|
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/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xregion.h> | 8 #include <X11/Xregion.h> |
9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "ui/aura/window_property.h" | 25 #include "ui/aura/window_property.h" |
26 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 26 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
27 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
28 #include "ui/base/ime/input_method.h" | 28 #include "ui/base/ime/input_method.h" |
29 #include "ui/base/x/x11_util.h" | 29 #include "ui/base/x/x11_util.h" |
30 #include "ui/base/x/x11_util_internal.h" | 30 #include "ui/base/x/x11_util_internal.h" |
31 #include "ui/events/devices/x11/device_data_manager_x11.h" | 31 #include "ui/events/devices/x11/device_data_manager_x11.h" |
32 #include "ui/events/devices/x11/device_list_cache_x11.h" | 32 #include "ui/events/devices/x11/device_list_cache_x11.h" |
33 #include "ui/events/devices/x11/touch_factory_x11.h" | 33 #include "ui/events/devices/x11/touch_factory_x11.h" |
34 #include "ui/events/event_utils.h" | 34 #include "ui/events/event_utils.h" |
35 #include "ui/events/null_event_targeter.h" | |
35 #include "ui/events/platform/platform_event_source.h" | 36 #include "ui/events/platform/platform_event_source.h" |
36 #include "ui/events/platform/x11/x11_event_source.h" | 37 #include "ui/events/platform/x11/x11_event_source.h" |
37 #include "ui/gfx/display.h" | 38 #include "ui/gfx/display.h" |
38 #include "ui/gfx/geometry/insets.h" | 39 #include "ui/gfx/geometry/insets.h" |
39 #include "ui/gfx/geometry/size_conversions.h" | 40 #include "ui/gfx/geometry/size_conversions.h" |
40 #include "ui/gfx/image/image_skia.h" | 41 #include "ui/gfx/image/image_skia.h" |
41 #include "ui/gfx/image/image_skia_rep.h" | 42 #include "ui/gfx/image/image_skia_rep.h" |
42 #include "ui/gfx/path.h" | 43 #include "ui/gfx/path.h" |
43 #include "ui/gfx/path_x11.h" | 44 #include "ui/gfx/path_x11.h" |
44 #include "ui/gfx/screen.h" | 45 #include "ui/gfx/screen.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 break; | 147 break; |
147 if (child_windows) | 148 if (child_windows) |
148 XFree(child_windows); | 149 XFree(child_windows); |
149 window = parent_win; | 150 window = parent_win; |
150 } | 151 } |
151 return result; | 152 return result; |
152 } | 153 } |
153 | 154 |
154 } // namespace | 155 } // namespace |
155 | 156 |
157 DesktopWindowTreeHostX11::ScopedHandle::ScopedHandle(const base::Closure& | |
158 destroy_callback) | |
159 : destroy_callback_(destroy_callback) { | |
160 } | |
161 | |
162 void DesktopWindowTreeHostX11::ScopedHandle::CancelCallback() { | |
163 if (!destroy_callback_.is_null()) | |
164 destroy_callback_.Reset(); | |
165 } | |
166 | |
167 DesktopWindowTreeHostX11::ScopedHandle::~ScopedHandle() { | |
168 if (!destroy_callback_.is_null()) | |
169 destroy_callback_.Run(); | |
170 } | |
171 | |
156 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
157 // DesktopWindowTreeHostX11, public: | 173 // DesktopWindowTreeHostX11, public: |
158 | 174 |
159 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( | 175 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( |
160 internal::NativeWidgetDelegate* native_widget_delegate, | 176 internal::NativeWidgetDelegate* native_widget_delegate, |
161 DesktopNativeWidgetAura* desktop_native_widget_aura) | 177 DesktopNativeWidgetAura* desktop_native_widget_aura) |
162 : xdisplay_(gfx::GetXDisplay()), | 178 : xdisplay_(gfx::GetXDisplay()), |
163 xwindow_(0), | 179 xwindow_(0), |
164 x_root_window_(DefaultRootWindow(xdisplay_)), | 180 x_root_window_(DefaultRootWindow(xdisplay_)), |
165 atom_cache_(xdisplay_, kAtomsToCache), | 181 atom_cache_(xdisplay_, kAtomsToCache), |
166 window_mapped_(false), | 182 window_mapped_(false), |
167 is_fullscreen_(false), | 183 is_fullscreen_(false), |
168 is_always_on_top_(false), | 184 is_always_on_top_(false), |
169 use_native_frame_(false), | 185 use_native_frame_(false), |
170 should_maximize_after_map_(false), | 186 should_maximize_after_map_(false), |
171 use_argb_visual_(false), | 187 use_argb_visual_(false), |
172 drag_drop_client_(NULL), | 188 drag_drop_client_(NULL), |
173 native_widget_delegate_(native_widget_delegate), | 189 native_widget_delegate_(native_widget_delegate), |
174 desktop_native_widget_aura_(desktop_native_widget_aura), | 190 desktop_native_widget_aura_(desktop_native_widget_aura), |
175 content_window_(NULL), | 191 content_window_(NULL), |
176 window_parent_(NULL), | 192 window_parent_(NULL), |
177 custom_window_shape_(false), | 193 custom_window_shape_(false), |
178 urgency_hint_set_(false), | 194 urgency_hint_set_(false), |
179 activatable_(true), | 195 activatable_(true), |
196 modal_dialog_xid_(0), | |
197 scoped_handle_(NULL), | |
180 close_widget_factory_(this) { | 198 close_widget_factory_(this) { |
181 } | 199 } |
182 | 200 |
183 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { | 201 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { |
184 window()->ClearProperty(kHostForRootWindow); | 202 window()->ClearProperty(kHostForRootWindow); |
185 aura::client::SetWindowMoveClient(window(), NULL); | 203 aura::client::SetWindowMoveClient(window(), NULL); |
186 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 204 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
187 DestroyDispatcher(); | 205 DestroyDispatcher(); |
188 } | 206 } |
189 | 207 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 drag_drop_client_ = new DesktopDragDropClientAuraX11( | 349 drag_drop_client_ = new DesktopDragDropClientAuraX11( |
332 window(), cursor_manager, xdisplay_, xwindow_); | 350 window(), cursor_manager, xdisplay_, xwindow_); |
333 drag_drop_client_->Init(); | 351 drag_drop_client_->Init(); |
334 return base::WrapUnique(drag_drop_client_); | 352 return base::WrapUnique(drag_drop_client_); |
335 } | 353 } |
336 | 354 |
337 void DesktopWindowTreeHostX11::Close() { | 355 void DesktopWindowTreeHostX11::Close() { |
338 // TODO(erg): Might need to do additional hiding tasks here. | 356 // TODO(erg): Might need to do additional hiding tasks here. |
339 delayed_resize_task_.Cancel(); | 357 delayed_resize_task_.Cancel(); |
340 | 358 |
359 // We should cancel the callback function when trying to close | |
360 // the host window while opening the file-picker, which allows | |
361 // to invalidate weak pointers of |close_widget_factory_|. | |
362 if (targeter_for_modal_) | |
363 scoped_handle_->CancelCallback(); | |
joone
2016/04/21 20:45:45
I added CancelCallback method to fix the problem t
sadrul
2016/05/11 05:27:47
I am not sure I understand this well. What happens
joone
2016/05/11 19:18:05
This file-pick is still opened after closing the h
sadrul
2016/05/11 19:20:36
If this host-window is closed, then that would inv
| |
364 | |
341 if (!close_widget_factory_.HasWeakPtrs()) { | 365 if (!close_widget_factory_.HasWeakPtrs()) { |
342 // And we delay the close so that if we are called from an ATL callback, | 366 // And we delay the close so that if we are called from an ATL callback, |
343 // we don't destroy the window before the callback returned (as the caller | 367 // we don't destroy the window before the callback returned (as the caller |
344 // may delete ourselves on destroy and the ATL callback would still | 368 // may delete ourselves on destroy and the ATL callback would still |
345 // dereference us when the callback returns). | 369 // dereference us when the callback returns). |
346 base::MessageLoop::current()->PostTask( | 370 base::MessageLoop::current()->PostTask( |
347 FROM_HERE, | 371 FROM_HERE, |
348 base::Bind(&DesktopWindowTreeHostX11::CloseNow, | 372 base::Bind(&DesktopWindowTreeHostX11::CloseNow, |
349 close_widget_factory_.GetWeakPtr())); | 373 close_widget_factory_.GetWeakPtr())); |
350 } | 374 } |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 if (g_current_capture && g_current_capture != this && | 1544 if (g_current_capture && g_current_capture != this && |
1521 event->type() == ui::ET_TOUCH_PRESSED) { | 1545 event->type() == ui::ET_TOUCH_PRESSED) { |
1522 ConvertEventToDifferentHost(event, g_current_capture); | 1546 ConvertEventToDifferentHost(event, g_current_capture); |
1523 g_current_capture->SendEventToProcessor(event); | 1547 g_current_capture->SendEventToProcessor(event); |
1524 } else { | 1548 } else { |
1525 SendEventToProcessor(event); | 1549 SendEventToProcessor(event); |
1526 } | 1550 } |
1527 } | 1551 } |
1528 | 1552 |
1529 void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) { | 1553 void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) { |
1530 GetInputMethod()->DispatchKeyEvent(event); | 1554 if (native_widget_delegate_->AsWidget()->IsActive()) |
1555 GetInputMethod()->DispatchKeyEvent(event); | |
1531 } | 1556 } |
1532 | 1557 |
1533 void DesktopWindowTreeHostX11::ConvertEventToDifferentHost( | 1558 void DesktopWindowTreeHostX11::ConvertEventToDifferentHost( |
1534 ui::LocatedEvent* located_event, | 1559 ui::LocatedEvent* located_event, |
1535 DesktopWindowTreeHostX11* host) { | 1560 DesktopWindowTreeHostX11* host) { |
1536 DCHECK_NE(this, host); | 1561 DCHECK_NE(this, host); |
1537 const gfx::Display display_src = | 1562 const gfx::Display display_src = |
1538 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window()); | 1563 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window()); |
1539 const gfx::Display display_dest = | 1564 const gfx::Display display_dest = |
1540 gfx::Screen::GetScreen()->GetDisplayNearestWindow(host->window()); | 1565 gfx::Screen::GetScreen()->GetDisplayNearestWindow(host->window()); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2015 return gfx::ToEnclosingRect(rect_in_dip); | 2040 return gfx::ToEnclosingRect(rect_in_dip); |
2016 } | 2041 } |
2017 | 2042 |
2018 gfx::Rect DesktopWindowTreeHostX11::ToPixelRect( | 2043 gfx::Rect DesktopWindowTreeHostX11::ToPixelRect( |
2019 const gfx::Rect& rect_in_dip) const { | 2044 const gfx::Rect& rect_in_dip) const { |
2020 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip); | 2045 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip); |
2021 GetRootTransform().TransformRect(&rect_in_pixels); | 2046 GetRootTransform().TransformRect(&rect_in_pixels); |
2022 return gfx::ToEnclosingRect(rect_in_pixels); | 2047 return gfx::ToEnclosingRect(rect_in_pixels); |
2023 } | 2048 } |
2024 | 2049 |
2050 XID DesktopWindowTreeHostX11::GetModalDialog() { | |
2051 return modal_dialog_xid_; | |
2052 } | |
2053 | |
2054 std::unique_ptr<DesktopWindowTreeHostX11::ScopedHandle> | |
2055 DesktopWindowTreeHostX11::DisableEventListening(XID dialog) { | |
2056 DCHECK(dialog); | |
2057 DCHECK(!modal_dialog_xid_); | |
2058 modal_dialog_xid_ = dialog; | |
2059 // ScopedWindowTargeter is used to temporarily replace the event-targeter | |
2060 // with NullEventTargeter to make |dialog| modal. | |
2061 targeter_for_modal_.reset(new aura::ScopedWindowTargeter(window(), | |
2062 std::unique_ptr<ui::EventTargeter>(new ui::NullEventTargeter))); | |
2063 | |
2064 scoped_handle_ = new DesktopWindowTreeHostX11::ScopedHandle( | |
2065 base::Bind(&DesktopWindowTreeHostX11::EnableEventListening, | |
2066 close_widget_factory_.GetWeakPtr())); | |
2067 return base::WrapUnique(scoped_handle_); | |
2068 } | |
2069 | |
2070 void DesktopWindowTreeHostX11::EnableEventListening() { | |
2071 DCHECK(modal_dialog_xid_); | |
2072 modal_dialog_xid_ = 0; | |
2073 targeter_for_modal_.reset(); | |
2074 } | |
2075 | |
2025 //////////////////////////////////////////////////////////////////////////////// | 2076 //////////////////////////////////////////////////////////////////////////////// |
2026 // DesktopWindowTreeHost, public: | 2077 // DesktopWindowTreeHost, public: |
2027 | 2078 |
2028 // static | 2079 // static |
2029 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( | 2080 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( |
2030 internal::NativeWidgetDelegate* native_widget_delegate, | 2081 internal::NativeWidgetDelegate* native_widget_delegate, |
2031 DesktopNativeWidgetAura* desktop_native_widget_aura) { | 2082 DesktopNativeWidgetAura* desktop_native_widget_aura) { |
2032 return new DesktopWindowTreeHostX11(native_widget_delegate, | 2083 return new DesktopWindowTreeHostX11(native_widget_delegate, |
2033 desktop_native_widget_aura); | 2084 desktop_native_widget_aura); |
2034 } | 2085 } |
2035 | 2086 |
2036 // static | 2087 // static |
2037 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { | 2088 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { |
2038 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 2089 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
2039 if (linux_ui) { | 2090 if (linux_ui) { |
2040 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2091 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
2041 if (native_theme) | 2092 if (native_theme) |
2042 return native_theme; | 2093 return native_theme; |
2043 } | 2094 } |
2044 | 2095 |
2045 return ui::NativeThemeAura::instance(); | 2096 return ui::NativeThemeAura::instance(); |
2046 } | 2097 } |
2047 | 2098 |
2048 } // namespace views | 2099 } // namespace views |
OLD | NEW |