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 @@
#include "ash/wm/workspace/phantom_window_controller.h"
#include "ash/wm/workspace/workspace_window_resizer.h"
#include "base/command_line.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
......@@ -47,8 +48,6 @@ DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint(
} // namespace
DockedWindowResizer::~DockedWindowResizer() {
if (destroyed_)
*destroyed_ = true;
}
// static
......@@ -66,7 +65,6 @@ DockedWindowResizer::Create(WindowResizer* next_window_resizer,
void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) {
last_location_ = location;
wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
bool destroyed = false;
if (!did_move_or_resize_) {
did_move_or_resize_ = true;
StartedDragging();
......@@ -83,15 +81,12 @@ void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) {
SetTrackedByWorkspace(GetTarget(), false);
gfx::Point modified_location(location.x() + offset.x(),
location.y() + offset.y());
destroyed_ = &destroyed;
next_window_resizer_->Drag(modified_location, event_flags);
// TODO(varkha): 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)
base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
next_window_resizer_->Drag(modified_location, event_flags);
if (!resizer)
return;
destroyed_ = NULL;
if (set_tracked_by_workspace)
SetTrackedByWorkspace(GetTarget(), tracked_by_workspace);
......@@ -185,7 +180,7 @@ DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer,
did_move_or_resize_(false),
was_docked_(false),
is_docked_(false),
destroyed_(NULL) {
weak_ptr_factory_(this) {
DCHECK(details_.is_resizable);
aura::Window* dock_container = Shell::GetContainer(
details.window->GetRootWindow(),
......
......@@ -9,6 +9,7 @@
#include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
namespace gfx {
class Point;
......@@ -98,9 +99,7 @@ class ASH_EXPORT DockedWindowResizer : public WindowResizer {
// True if the dragged window is docked during the drag.
bool is_docked_;
// If non-NULL the destructor sets this to true. Used to determine if this has
// been deleted.
bool* destroyed_;
base::WeakPtrFactory<DockedWindowResizer> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DockedWindowResizer);
};
......
......@@ -10,6 +10,7 @@
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/drag_window_controller.h"
#include "ash/wm/property_util.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
......@@ -56,9 +57,6 @@ DragWindowResizer::~DragWindowResizer() {
shell->mouse_cursor_filter()->HideSharedEdgeIndicator();
if (instance_ == this)
instance_ = NULL;
if (destroyed_)
*destroyed_ = true;
}
// static
......@@ -74,18 +72,12 @@ DragWindowResizer* DragWindowResizer::Create(
}
void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) {
bool destroyed = false;
destroyed_ = &destroyed;
base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
next_window_resizer_->Drag(location, event_flags);
// 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)
if (!resizer)
return;
destroyed_ = NULL;
last_mouse_location_ = location;
last_mouse_location_ = location;
// Show a phantom window for dragging in another root window.
if (HasSecondaryRootWindow()) {
gfx::Point location_in_screen = location;
......@@ -140,7 +132,7 @@ DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer,
const Details& details)
: next_window_resizer_(next_window_resizer),
details_(details),
destroyed_(NULL) {
weak_ptr_factory_(this) {
// 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
// exception is window/tab dragging operation. During that operation,
......
......@@ -8,6 +8,7 @@
#include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "ui/gfx/point.h"
namespace ash {
......@@ -62,13 +63,11 @@ class ASH_EXPORT DragWindowResizer : public WindowResizer {
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.
static DragWindowResizer* instance_;
base::WeakPtrFactory<DragWindowResizer> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DragWindowResizer);
};
......
......@@ -15,6 +15,7 @@
#include "ash/wm/panels/panel_layout_manager.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_properties.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
......@@ -40,8 +41,6 @@ internal::PanelLayoutManager* GetPanelLayoutManager(
} // namespace
PanelWindowResizer::~PanelWindowResizer() {
if (destroyed_)
*destroyed_ = true;
}
// static
......@@ -59,7 +58,6 @@ PanelWindowResizer::Create(WindowResizer* next_window_resizer,
void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
last_location_ = location;
wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
bool destroyed = false;
if (!did_move_or_resize_) {
did_move_or_resize_ = true;
StartedDragging();
......@@ -93,15 +91,12 @@ void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
should_attach_ = AttachToLauncher(bounds, &offset);
gfx::Point modified_location(location.x() + offset.x(),
location.y() + offset.y());
destroyed_ = &destroyed;
next_window_resizer_->Drag(modified_location, event_flags);
// 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)
base::WeakPtr<PanelWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
next_window_resizer_->Drag(modified_location, event_flags);
if (!resizer)
return;
destroyed_ = NULL;
if (should_attach_ &&
!(details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) {
UpdateLauncherPosition();
......@@ -137,7 +132,7 @@ PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer,
did_move_or_resize_(false),
was_attached_(GetTarget()->GetProperty(internal::kPanelAttachedKey)),
should_attach_(was_attached_),
destroyed_(NULL) {
weak_ptr_factory_(this) {
DCHECK(details_.is_resizable);
panel_container_ = Shell::GetContainer(
details.window->GetRootWindow(),
......
......@@ -7,6 +7,7 @@
#include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
namespace gfx {
class Rect;
......@@ -83,9 +84,7 @@ class ASH_EXPORT PanelWindowResizer : public WindowResizer {
// True if the window should attach to the launcher after releasing.
bool should_attach_;
// If non-NULL the destructor sets this to true. Used to determine if this has
// been deleted.
bool* destroyed_;
base::WeakPtrFactory<PanelWindowResizer> weak_ptr_factory_;
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