Commit 1e87e370 authored by flackr@chromium.org's avatar flackr@chromium.org

Use a weak pointer to determine if resizer was destroyed by nested Drag calls.

BUG=None
TEST=*ResizerTest.*

Review URL: https://chromiumcodereview.appspot.com/23645008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221790 0039d316-1c4b-4281-b951-d872f2087c98
parent d9199870
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ash/wm/workspace/phantom_window_controller.h" #include "ash/wm/workspace/phantom_window_controller.h"
#include "ash/wm/workspace/workspace_window_resizer.h" #include "ash/wm/workspace/workspace_window_resizer.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
...@@ -47,8 +48,6 @@ DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( ...@@ -47,8 +48,6 @@ DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint(
} // namespace } // namespace
DockedWindowResizer::~DockedWindowResizer() { DockedWindowResizer::~DockedWindowResizer() {
if (destroyed_)
*destroyed_ = true;
} }
// static // static
...@@ -66,7 +65,6 @@ DockedWindowResizer::Create(WindowResizer* next_window_resizer, ...@@ -66,7 +65,6 @@ DockedWindowResizer::Create(WindowResizer* next_window_resizer,
void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) {
last_location_ = location; last_location_ = location;
wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
bool destroyed = false;
if (!did_move_or_resize_) { if (!did_move_or_resize_) {
did_move_or_resize_ = true; did_move_or_resize_ = true;
StartedDragging(); StartedDragging();
...@@ -83,15 +81,12 @@ void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { ...@@ -83,15 +81,12 @@ void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) {
SetTrackedByWorkspace(GetTarget(), false); SetTrackedByWorkspace(GetTarget(), false);
gfx::Point modified_location(location.x() + offset.x(), gfx::Point modified_location(location.x() + offset.x(),
location.y() + offset.y()); location.y() + offset.y());
destroyed_ = &destroyed;
next_window_resizer_->Drag(modified_location, event_flags);
// TODO(varkha): Refactor the way WindowResizer calls into other window base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
// resizers to avoid the awkward pattern here for checking if next_window_resizer_->Drag(modified_location, event_flags);
// next_window_resizer_ destroys the resizer object. if (!resizer)
if (destroyed)
return; return;
destroyed_ = NULL;
if (set_tracked_by_workspace) if (set_tracked_by_workspace)
SetTrackedByWorkspace(GetTarget(), tracked_by_workspace); SetTrackedByWorkspace(GetTarget(), tracked_by_workspace);
...@@ -185,7 +180,7 @@ DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, ...@@ -185,7 +180,7 @@ DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer,
did_move_or_resize_(false), did_move_or_resize_(false),
was_docked_(false), was_docked_(false),
is_docked_(false), is_docked_(false),
destroyed_(NULL) { weak_ptr_factory_(this) {
DCHECK(details_.is_resizable); DCHECK(details_.is_resizable);
aura::Window* dock_container = Shell::GetContainer( aura::Window* dock_container = Shell::GetContainer(
details.window->GetRootWindow(), details.window->GetRootWindow(),
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/wm/window_resizer.h" #include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
namespace gfx { namespace gfx {
class Point; class Point;
...@@ -98,9 +99,7 @@ class ASH_EXPORT DockedWindowResizer : public WindowResizer { ...@@ -98,9 +99,7 @@ class ASH_EXPORT DockedWindowResizer : public WindowResizer {
// True if the dragged window is docked during the drag. // True if the dragged window is docked during the drag.
bool is_docked_; bool is_docked_;
// If non-NULL the destructor sets this to true. Used to determine if this has base::WeakPtrFactory<DockedWindowResizer> weak_ptr_factory_;
// been deleted.
bool* destroyed_;
DISALLOW_COPY_AND_ASSIGN(DockedWindowResizer); DISALLOW_COPY_AND_ASSIGN(DockedWindowResizer);
}; };
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/wm/coordinate_conversion.h" #include "ash/wm/coordinate_conversion.h"
#include "ash/wm/drag_window_controller.h" #include "ash/wm/drag_window_controller.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
...@@ -56,9 +57,6 @@ DragWindowResizer::~DragWindowResizer() { ...@@ -56,9 +57,6 @@ DragWindowResizer::~DragWindowResizer() {
shell->mouse_cursor_filter()->HideSharedEdgeIndicator(); shell->mouse_cursor_filter()->HideSharedEdgeIndicator();
if (instance_ == this) if (instance_ == this)
instance_ = NULL; instance_ = NULL;
if (destroyed_)
*destroyed_ = true;
} }
// static // static
...@@ -74,18 +72,12 @@ DragWindowResizer* DragWindowResizer::Create( ...@@ -74,18 +72,12 @@ DragWindowResizer* DragWindowResizer::Create(
} }
void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) {
bool destroyed = false; base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
destroyed_ = &destroyed;
next_window_resizer_->Drag(location, event_flags); next_window_resizer_->Drag(location, event_flags);
if (!resizer)
// TODO(flackr): Refactor the way WindowResizer calls into other window
// resizers to avoid the awkward pattern here for checking if
// next_window_resizer_ destroys the resizer object.
if (destroyed)
return; return;
destroyed_ = NULL;
last_mouse_location_ = location;
last_mouse_location_ = location;
// Show a phantom window for dragging in another root window. // Show a phantom window for dragging in another root window.
if (HasSecondaryRootWindow()) { if (HasSecondaryRootWindow()) {
gfx::Point location_in_screen = location; gfx::Point location_in_screen = location;
...@@ -140,7 +132,7 @@ DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, ...@@ -140,7 +132,7 @@ DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer,
const Details& details) const Details& details)
: next_window_resizer_(next_window_resizer), : next_window_resizer_(next_window_resizer),
details_(details), details_(details),
destroyed_(NULL) { weak_ptr_factory_(this) {
// The pointer should be confined in one display during resizing a window // The pointer should be confined in one display during resizing a window
// because the window cannot span two displays at the same time anyway. The // because the window cannot span two displays at the same time anyway. The
// exception is window/tab dragging operation. During that operation, // exception is window/tab dragging operation. During that operation,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/wm/window_resizer.h" #include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
namespace ash { namespace ash {
...@@ -62,13 +63,11 @@ class ASH_EXPORT DragWindowResizer : public WindowResizer { ...@@ -62,13 +63,11 @@ class ASH_EXPORT DragWindowResizer : public WindowResizer {
gfx::Point last_mouse_location_; gfx::Point last_mouse_location_;
// If non-NULL the destructor sets this to true. Used to determine if this has
// been deleted.
bool* destroyed_;
// Current instance for use by the DragWindowResizerTest. // Current instance for use by the DragWindowResizerTest.
static DragWindowResizer* instance_; static DragWindowResizer* instance_;
base::WeakPtrFactory<DragWindowResizer> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DragWindowResizer); DISALLOW_COPY_AND_ASSIGN(DragWindowResizer);
}; };
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/wm/panels/panel_layout_manager.h" #include "ash/wm/panels/panel_layout_manager.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
#include "ash/wm/window_properties.h" #include "ash/wm/window_properties.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
...@@ -40,8 +41,6 @@ internal::PanelLayoutManager* GetPanelLayoutManager( ...@@ -40,8 +41,6 @@ internal::PanelLayoutManager* GetPanelLayoutManager(
} // namespace } // namespace
PanelWindowResizer::~PanelWindowResizer() { PanelWindowResizer::~PanelWindowResizer() {
if (destroyed_)
*destroyed_ = true;
} }
// static // static
...@@ -59,7 +58,6 @@ PanelWindowResizer::Create(WindowResizer* next_window_resizer, ...@@ -59,7 +58,6 @@ PanelWindowResizer::Create(WindowResizer* next_window_resizer,
void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
last_location_ = location; last_location_ = location;
wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
bool destroyed = false;
if (!did_move_or_resize_) { if (!did_move_or_resize_) {
did_move_or_resize_ = true; did_move_or_resize_ = true;
StartedDragging(); StartedDragging();
...@@ -93,15 +91,12 @@ void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { ...@@ -93,15 +91,12 @@ void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
should_attach_ = AttachToLauncher(bounds, &offset); should_attach_ = AttachToLauncher(bounds, &offset);
gfx::Point modified_location(location.x() + offset.x(), gfx::Point modified_location(location.x() + offset.x(),
location.y() + offset.y()); location.y() + offset.y());
destroyed_ = &destroyed;
next_window_resizer_->Drag(modified_location, event_flags);
// TODO(flackr): Refactor the way WindowResizer calls into other window base::WeakPtr<PanelWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
// resizers to avoid the awkward pattern here for checking if next_window_resizer_->Drag(modified_location, event_flags);
// next_window_resizer_ destroys the resizer object. if (!resizer)
if (destroyed)
return; return;
destroyed_ = NULL;
if (should_attach_ && if (should_attach_ &&
!(details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) { !(details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) {
UpdateLauncherPosition(); UpdateLauncherPosition();
...@@ -137,7 +132,7 @@ PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, ...@@ -137,7 +132,7 @@ PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer,
did_move_or_resize_(false), did_move_or_resize_(false),
was_attached_(GetTarget()->GetProperty(internal::kPanelAttachedKey)), was_attached_(GetTarget()->GetProperty(internal::kPanelAttachedKey)),
should_attach_(was_attached_), should_attach_(was_attached_),
destroyed_(NULL) { weak_ptr_factory_(this) {
DCHECK(details_.is_resizable); DCHECK(details_.is_resizable);
panel_container_ = Shell::GetContainer( panel_container_ = Shell::GetContainer(
details.window->GetRootWindow(), details.window->GetRootWindow(),
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/wm/window_resizer.h" #include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
namespace gfx { namespace gfx {
class Rect; class Rect;
...@@ -83,9 +84,7 @@ class ASH_EXPORT PanelWindowResizer : public WindowResizer { ...@@ -83,9 +84,7 @@ class ASH_EXPORT PanelWindowResizer : public WindowResizer {
// True if the window should attach to the launcher after releasing. // True if the window should attach to the launcher after releasing.
bool should_attach_; bool should_attach_;
// If non-NULL the destructor sets this to true. Used to determine if this has base::WeakPtrFactory<PanelWindowResizer> weak_ptr_factory_;
// been deleted.
bool* destroyed_;
DISALLOW_COPY_AND_ASSIGN(PanelWindowResizer); DISALLOW_COPY_AND_ASSIGN(PanelWindowResizer);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment