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

Unified 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: Can close the host window while opening the file-picker Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index 32092cffdf11e018a8929855812b8fe0e7204b82..5e9abb3a667aab398a656d0417711f96dee99c66 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -32,6 +32,7 @@
#include "ui/events/devices/x11/device_list_cache_x11.h"
#include "ui/events/devices/x11/touch_factory_x11.h"
#include "ui/events/event_utils.h"
+#include "ui/events/null_event_targeter.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/display.h"
@@ -153,6 +154,21 @@ std::vector<::Window> GetParentsList(XDisplay* xdisplay, ::Window window) {
} // namespace
+DesktopWindowTreeHostX11::ScopedHandle::ScopedHandle(const base::Closure&
+ destroy_callback)
+ : destroy_callback_(destroy_callback) {
+}
+
+void DesktopWindowTreeHostX11::ScopedHandle::CancelCallback() {
+ if (!destroy_callback_.is_null())
+ destroy_callback_.Reset();
+}
+
+DesktopWindowTreeHostX11::ScopedHandle::~ScopedHandle() {
+ if (!destroy_callback_.is_null())
+ destroy_callback_.Run();
+}
+
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, public:
@@ -177,6 +193,8 @@ DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
custom_window_shape_(false),
urgency_hint_set_(false),
activatable_(true),
+ modal_dialog_xid_(0),
+ scoped_handle_(NULL),
close_widget_factory_(this) {
}
@@ -338,6 +356,12 @@ void DesktopWindowTreeHostX11::Close() {
// TODO(erg): Might need to do additional hiding tasks here.
delayed_resize_task_.Cancel();
+ // We should cancel the callback function when trying to close
+ // the host window while opening the file-picker, which allows
+ // to invalidate weak pointers of |close_widget_factory_|.
+ if (targeter_for_modal_)
+ 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
+
if (!close_widget_factory_.HasWeakPtrs()) {
// And we delay the close so that if we are called from an ATL callback,
// we don't destroy the window before the callback returned (as the caller
@@ -1527,7 +1551,8 @@ void DesktopWindowTreeHostX11::DispatchTouchEvent(ui::TouchEvent* event) {
}
void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) {
- GetInputMethod()->DispatchKeyEvent(event);
+ if (native_widget_delegate_->AsWidget()->IsActive())
+ GetInputMethod()->DispatchKeyEvent(event);
}
void DesktopWindowTreeHostX11::ConvertEventToDifferentHost(
@@ -2022,6 +2047,32 @@ gfx::Rect DesktopWindowTreeHostX11::ToPixelRect(
return gfx::ToEnclosingRect(rect_in_pixels);
}
+XID DesktopWindowTreeHostX11::GetModalDialog() {
+ return modal_dialog_xid_;
+}
+
+std::unique_ptr<DesktopWindowTreeHostX11::ScopedHandle>
+ DesktopWindowTreeHostX11::DisableEventListening(XID dialog) {
+ DCHECK(dialog);
+ DCHECK(!modal_dialog_xid_);
+ modal_dialog_xid_ = dialog;
+ // ScopedWindowTargeter is used to temporarily replace the event-targeter
+ // with NullEventTargeter to make |dialog| modal.
+ targeter_for_modal_.reset(new aura::ScopedWindowTargeter(window(),
+ std::unique_ptr<ui::EventTargeter>(new ui::NullEventTargeter)));
+
+ scoped_handle_ = new DesktopWindowTreeHostX11::ScopedHandle(
+ base::Bind(&DesktopWindowTreeHostX11::EnableEventListening,
+ close_widget_factory_.GetWeakPtr()));
+ return base::WrapUnique(scoped_handle_);
+}
+
+void DesktopWindowTreeHostX11::EnableEventListening() {
+ DCHECK(modal_dialog_xid_);
+ modal_dialog_xid_ = 0;
+ targeter_for_modal_.reset();
+}
+
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost, public:

Powered by Google App Engine
This is Rietveld 408576698