diff options
author | ginkage <ginkage@chromium.org> | 2015-03-13 14:20:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-13 21:21:44 +0000 |
commit | e8d70324934f3a561cee491cb0c1526ecbef498d (patch) | |
tree | 8fee528fa9128b8b4812184e9bcd1abe356a28b5 /ui/wm | |
parent | 884a7f0a7db9c0d7c95038e191a2c0d1c9920f2b (diff) | |
download | chromium_src-e8d70324934f3a561cee491cb0c1526ecbef498d.zip chromium_src-e8d70324934f3a561cee491cb0c1526ecbef498d.tar.gz chromium_src-e8d70324934f3a561cee491cb0c1526ecbef498d.tar.bz2 |
Disable drag-and-drop on login flow to avoid hanging.
BUG=464118
TEST=manual
Review URL: https://codereview.chromium.org/992173004
Cr-Commit-Position: refs/heads/master@{#320574}
Diffstat (limited to 'ui/wm')
-rw-r--r-- | ui/wm/public/scoped_drag_drop_disabler.cc | 55 | ||||
-rw-r--r-- | ui/wm/public/scoped_drag_drop_disabler.h | 40 |
2 files changed, 95 insertions, 0 deletions
diff --git a/ui/wm/public/scoped_drag_drop_disabler.cc b/ui/wm/public/scoped_drag_drop_disabler.cc new file mode 100644 index 0000000..aaeb56d --- /dev/null +++ b/ui/wm/public/scoped_drag_drop_disabler.cc @@ -0,0 +1,55 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/scoped_drag_drop_disabler.h" + +#include "ui/aura/window.h" +#include "ui/wm/public/drag_drop_client.h" + +namespace aura { +namespace client { + +class NopDragDropClient : public DragDropClient { + public: + ~NopDragDropClient() override {} + int StartDragAndDrop(const ui::OSExchangeData& data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int operation, + ui::DragDropTypes::DragEventSource source) override { + return 0; + } + void DragUpdate(aura::Window* target, + const ui::LocatedEvent& event) override {} + void Drop(aura::Window* target, const ui::LocatedEvent& event) override {} + void DragCancel() override {} + bool IsDragDropInProgress() override { + return false; + } +}; + +ScopedDragDropDisabler::ScopedDragDropDisabler(Window* window) + : window_(window), + old_client_(GetDragDropClient(window)), + new_client_(new NopDragDropClient()) { + SetDragDropClient(window_, new_client_.get()); + window_->AddObserver(this); +} + +ScopedDragDropDisabler::~ScopedDragDropDisabler() { + if (window_) { + window_->RemoveObserver(this); + SetDragDropClient(window_, old_client_); + } +} + +void ScopedDragDropDisabler::OnWindowDestroyed(Window* window) { + CHECK_EQ(window_, window); + window_ = NULL; + new_client_.reset(); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/scoped_drag_drop_disabler.h b/ui/wm/public/scoped_drag_drop_disabler.h new file mode 100644 index 0000000..4f708ee --- /dev/null +++ b/ui/wm/public/scoped_drag_drop_disabler.h @@ -0,0 +1,40 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_SCOPED_DRAG_DROP_DISABLER_H_ +#define UI_WM_PUBLIC_SCOPED_DRAG_DROP_DISABLER_H_ + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "ui/aura/window_observer.h" + +namespace aura { +class Window; + +namespace client { +class DragDropClient; + +// ScopedDragDropDisabler is used to temporarily replace the drag'n'drop client +// for a window with a "no-op" client. Upon construction, it installs a new +// client on the window, and upon destruction, it restores the previous one. +class AURA_EXPORT ScopedDragDropDisabler : public WindowObserver { + public: + explicit ScopedDragDropDisabler(Window* window); + ~ScopedDragDropDisabler() override; + + private: + // WindowObserver: + void OnWindowDestroyed(Window* window) override; + + Window* window_; + DragDropClient* old_client_; + scoped_ptr<DragDropClient> new_client_; + + DISALLOW_COPY_AND_ASSIGN(ScopedDragDropDisabler); +}; + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_SCOPED_DRAG_DROP_DISABLER_H_ |