Commit 22228929 authored by sky@chromium.org's avatar sky@chromium.org

Minor refactoring of window resize code. I wasn't too happy with

continuing to have WindowResizer expose logic for
WorkspaceWindowResizer. Instead WindowResizer is pure virtual, with
some common code in static methods that both implementations can
use. This'll make the code for multi-window resizing more centralized.

BUG=116079
TEST=refactoring covered by tests
Review URL: https://chromiumcodereview.appspot.com/9599007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124939 0039d316-1c4b-4281-b951-d872f2087c98
parent 98ffde9b
...@@ -141,6 +141,8 @@ ...@@ -141,6 +141,8 @@
'wm/compact_layout_manager.h', 'wm/compact_layout_manager.h',
'wm/compact_status_area_layout_manager.cc', 'wm/compact_status_area_layout_manager.cc',
'wm/compact_status_area_layout_manager.h', 'wm/compact_status_area_layout_manager.h',
'wm/default_window_resizer.cc',
'wm/default_window_resizer.h',
'wm/dialog_frame_view.cc', 'wm/dialog_frame_view.cc',
'wm/dialog_frame_view.h', 'wm/dialog_frame_view.h',
'wm/image_grid.cc', 'wm/image_grid.cc',
......
// Copyright (c) 2012 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 "ash/wm/default_window_resizer.h"
#include "ash/shell.h"
#include "ash/wm/root_window_event_filter.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/screen.h"
namespace ash {
DefaultWindowResizer::~DefaultWindowResizer() {
if (root_filter_)
root_filter_->UnlockCursor();
}
// static
DefaultWindowResizer*
DefaultWindowResizer::Create(aura::Window* window,
const gfx::Point& location,
int window_component,
int grid_size) {
Details details(window, location, window_component, grid_size);
return details.is_resizable ? new DefaultWindowResizer(details) : NULL;
}
void DefaultWindowResizer::Drag(const gfx::Point& location) {
gfx::Rect bounds(CalculateBoundsForDrag(details_, location));
if (bounds != details_.window->bounds()) {
did_move_or_resize_ = true;
details_.window->SetBounds(bounds);
}
}
void DefaultWindowResizer::CompleteDrag() {
if (details_.grid_size <= 1 || !did_move_or_resize_)
return;
gfx::Rect new_bounds(AdjustBoundsToGrid(details_));
if (new_bounds == details_.window->bounds())
return;
if (new_bounds.size() != details_.window->bounds().size()) {
// Don't attempt to animate a size change.
details_.window->SetBounds(new_bounds);
return;
}
ui::ScopedLayerAnimationSettings scoped_setter(
details_.window->layer()->GetAnimator());
// Use a small duration since the grid is small.
scoped_setter.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
details_.window->SetBounds(new_bounds);
}
void DefaultWindowResizer::RevertDrag() {
if (!did_move_or_resize_)
return;
details_.window->SetBounds(details_.initial_bounds);
}
DefaultWindowResizer::DefaultWindowResizer(const Details& details)
: details_(details),
did_move_or_resize_(false),
root_filter_(NULL) {
DCHECK(details_.is_resizable);
root_filter_ = Shell::GetInstance()->root_filter();
if (root_filter_)
root_filter_->LockCursor();
}
} // namespace aura
// Copyright (c) 2012 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 ASH_WM_DEFAULT_WINDOW_RESIZER_H_
#define ASH_WM_DEFAULT_WINDOW_RESIZER_H_
#pragma once
#include "ash/wm/window_resizer.h"
#include "base/compiler_specific.h"
namespace ash {
namespace internal {
class RootWindowEventFilter;
}
// WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving
// or resizing a window. All coordinates passed to this are in the parent
// windows coordiantes.
class ASH_EXPORT DefaultWindowResizer : public WindowResizer {
public:
// Constants to identify the type of resize.
static const int kBoundsChange_None;
static const int kBoundsChange_Repositions;
static const int kBoundsChange_Resizes;
// Used to indicate which direction the resize occurs in.
static const int kBoundsChangeDirection_None;
static const int kBoundsChangeDirection_Horizontal;
static const int kBoundsChangeDirection_Vertical;
virtual ~DefaultWindowResizer();
// Creates a new DefaultWindowResizer. The caller takes ownership of the
// returned object. Returns NULL if not resizable.
static DefaultWindowResizer* Create(aura::Window* window,
const gfx::Point& location,
int window_component,
int grid_size);
// Returns true if the drag will result in changing the window in anyway.
bool is_resizable() const { return details_.is_resizable; }
// WindowResizer overides:
virtual void Drag(const gfx::Point& location) OVERRIDE;
virtual void CompleteDrag() OVERRIDE;
virtual void RevertDrag() OVERRIDE;
private:
explicit DefaultWindowResizer(const Details& details);
const Details details_;
// Set to true once Drag() is invoked and the bounds of the window change.
bool did_move_or_resize_;
internal::RootWindowEventFilter* root_filter_;
DISALLOW_COPY_AND_ASSIGN(DefaultWindowResizer);
};
} // namespace aura
#endif // ASH_WM_DEFAULT_WINDOW_RESIZER_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/wm/toplevel_window_event_filter.h" #include "ash/wm/toplevel_window_event_filter.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/default_window_resizer.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
#include "ash/wm/window_resizer.h" #include "ash/wm/window_resizer.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
...@@ -22,6 +23,17 @@ ...@@ -22,6 +23,17 @@
namespace ash { namespace ash {
namespace {
gfx::Point ConvertPointToParent(aura::Window* window,
const gfx::Point& point) {
gfx::Point result(point);
aura::Window::ConvertPointToWindow(window, window->parent(), &result);
return result;
}
}
ToplevelWindowEventFilter::ToplevelWindowEventFilter(aura::Window* owner) ToplevelWindowEventFilter::ToplevelWindowEventFilter(aura::Window* owner)
: in_move_loop_(false), : in_move_loop_(false),
in_gesture_resize_(false), in_gesture_resize_(false),
...@@ -51,10 +63,10 @@ bool ToplevelWindowEventFilter::PreHandleMouseEvent(aura::Window* target, ...@@ -51,10 +63,10 @@ bool ToplevelWindowEventFilter::PreHandleMouseEvent(aura::Window* target,
int component = int component =
target->delegate()->GetNonClientComponent(event->location()); target->delegate()->GetNonClientComponent(event->location());
if (WindowResizer::GetBoundsChangeForWindowComponent(component)) { if (WindowResizer::GetBoundsChangeForWindowComponent(component)) {
gfx::Point parent_location(
ConvertPointToParent(target, event->location()));
window_resizer_.reset( window_resizer_.reset(
CreateWindowResizer(target, event->location(), component)); CreateWindowResizer(target, parent_location, component));
if (window_resizer_.get() && !window_resizer_->is_resizable())
window_resizer_.reset();
} else { } else {
window_resizer_.reset(); window_resizer_.reset();
} }
...@@ -95,7 +107,8 @@ ui::TouchStatus ToplevelWindowEventFilter::PreHandleTouchEvent( ...@@ -95,7 +107,8 @@ ui::TouchStatus ToplevelWindowEventFilter::PreHandleTouchEvent(
} }
ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent( ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent(
aura::Window* target, aura::GestureEvent* event) { aura::Window* target,
aura::GestureEvent* event) {
switch (event->type()) { switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN: { case ui::ET_GESTURE_SCROLL_BEGIN: {
int component = int component =
...@@ -105,10 +118,10 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent( ...@@ -105,10 +118,10 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent(
return ui::GESTURE_STATUS_UNKNOWN; return ui::GESTURE_STATUS_UNKNOWN;
} }
in_gesture_resize_ = true; in_gesture_resize_ = true;
gfx::Point parent_location(
ConvertPointToParent(target, event->location()));
window_resizer_.reset( window_resizer_.reset(
CreateWindowResizer(target, event->location(), component)); CreateWindowResizer(target, parent_location, component));
if (window_resizer_.get() && !window_resizer_->is_resizable())
window_resizer_.reset();
break; break;
} }
case ui::ET_GESTURE_SCROLL_UPDATE: { case ui::ET_GESTURE_SCROLL_UPDATE: {
...@@ -134,11 +147,11 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent( ...@@ -134,11 +147,11 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent(
void ToplevelWindowEventFilter::RunMoveLoop(aura::Window* source) { void ToplevelWindowEventFilter::RunMoveLoop(aura::Window* source) {
DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. DCHECK(!in_move_loop_); // Can only handle one nested loop at a time.
in_move_loop_ = true; in_move_loop_ = true;
gfx::Point source_mouse_location(gfx::Screen::GetCursorScreenPoint()); gfx::Point parent_mouse_location(gfx::Screen::GetCursorScreenPoint());
aura::Window::ConvertPointToWindow( aura::Window::ConvertPointToWindow(
Shell::GetRootWindow(), source, &source_mouse_location); Shell::GetRootWindow(), source->parent(), &parent_mouse_location);
window_resizer_.reset( window_resizer_.reset(
CreateWindowResizer(source, source_mouse_location, HTCAPTION)); CreateWindowResizer(source, parent_mouse_location, HTCAPTION));
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
MessageLoopForUI::current()->RunWithDispatcher( MessageLoopForUI::current()->RunWithDispatcher(
aura::Env::GetInstance()->GetDispatcher()); aura::Env::GetInstance()->GetDispatcher());
...@@ -159,13 +172,15 @@ void ToplevelWindowEventFilter::EndMoveLoop() { ...@@ -159,13 +172,15 @@ void ToplevelWindowEventFilter::EndMoveLoop() {
Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent()); Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent());
} }
// static
WindowResizer* ToplevelWindowEventFilter::CreateWindowResizer( WindowResizer* ToplevelWindowEventFilter::CreateWindowResizer(
aura::Window* window, aura::Window* window,
const gfx::Point& point, const gfx::Point& point,
int window_component) { int window_component) {
if (!wm::IsWindowNormal(window)) if (!wm::IsWindowNormal(window))
return NULL; // Don't allow resizing/dragging maximized/fullscreen windows. return NULL; // Don't allow resizing/dragging maximized/fullscreen windows.
return new WindowResizer(window, point, window_component, grid_size_); return DefaultWindowResizer::Create(
window, point, window_component, grid_size_);
} }
void ToplevelWindowEventFilter::CompleteDrag(DragCompletionStatus status) { void ToplevelWindowEventFilter::CompleteDrag(DragCompletionStatus status) {
...@@ -188,7 +203,7 @@ bool ToplevelWindowEventFilter::HandleDrag(aura::Window* target, ...@@ -188,7 +203,7 @@ bool ToplevelWindowEventFilter::HandleDrag(aura::Window* target,
if (!window_resizer_.get()) if (!window_resizer_.get())
return false; return false;
window_resizer_->Drag(event->location()); window_resizer_->Drag(ConvertPointToParent(target, event->location()));
return true; return true;
} }
......
This diff is collapsed.
...@@ -16,12 +16,9 @@ class Window; ...@@ -16,12 +16,9 @@ class Window;
namespace ash { namespace ash {
namespace internal { // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving
class RootWindowEventFilter; // or resizing a window. All coordinates passed to this are in the parent
} // windows coordinates.
// WindowResizer is used by ToplevelWindowEventFilter to handle dragging,
// moving or resizing a window.
class ASH_EXPORT WindowResizer { class ASH_EXPORT WindowResizer {
public: public:
// Constants to identify the type of resize. // Constants to identify the type of resize.
...@@ -34,10 +31,7 @@ class ASH_EXPORT WindowResizer { ...@@ -34,10 +31,7 @@ class ASH_EXPORT WindowResizer {
static const int kBoundsChangeDirection_Horizontal; static const int kBoundsChangeDirection_Horizontal;
static const int kBoundsChangeDirection_Vertical; static const int kBoundsChangeDirection_Vertical;
WindowResizer(aura::Window* window, WindowResizer();
const gfx::Point& location,
int window_component,
int grid_size);
virtual ~WindowResizer(); virtual ~WindowResizer();
// Returns a bitmask of the kBoundsChange_ values. // Returns a bitmask of the kBoundsChange_ values.
...@@ -49,84 +43,80 @@ class ASH_EXPORT WindowResizer { ...@@ -49,84 +43,80 @@ class ASH_EXPORT WindowResizer {
// Invoked to drag/move/resize the window. |location| is in the coordinates // Invoked to drag/move/resize the window. |location| is in the coordinates
// of the window supplied to the constructor. // of the window supplied to the constructor.
void Drag(const gfx::Point& location); virtual void Drag(const gfx::Point& location) = 0;
// Invoked to complete the drag. // Invoked to complete the drag.
virtual void CompleteDrag(); virtual void CompleteDrag() = 0;
// Reverts the drag. // Reverts the drag.
virtual void RevertDrag(); virtual void RevertDrag() = 0;
// Returns true if the drag will result in changing the window in anyway.
bool is_resizable() const { return is_resizable_; }
// See description above members for details.
const gfx::Rect& initial_bounds() const { return initial_bounds_; }
const gfx::Point& initial_location_in_parent() const {
return initial_location_in_parent_;
}
int window_component() const { return window_component_; }
aura::Window* window() const { return window_; }
int grid_size() const { return grid_size_; }
bool did_move_or_resize() const { return did_move_or_resize_; }
int bounds_change() const { return bounds_change_; }
protected: protected:
// Returns the bounds to give to the window once the mouse has moved to struct Details {
// |location|. Details();
virtual gfx::Rect GetBoundsForDrag(const gfx::Point& location); Details(aura::Window* window,
const gfx::Point& location,
// Returns the final bounds. This differs from current bounds if a grid_size int window_component,
// was specified. int grid_size);
virtual gfx::Rect GetFinalBounds(); ~Details();
private:
// Returns the new origin of the window. The arguments are the difference
// between the current location and the initial location.
gfx::Point GetOriginForDrag(int delta_x, int delta_y) const;
// Returns the size of the window for the drag.
gfx::Size GetSizeForDrag(int* delta_x, int* delta_y) const;
// Returns the width of the window.
int GetWidthForDrag(int min_width, int* delta_x) const;
// Returns the height of the drag.
int GetHeightForDrag(int min_height, int* delta_y) const;
// The window we're resizing. // The window we're resizing.
aura::Window* window_; aura::Window* window;
// Initial bounds of the window. // Initial bounds of the window.
const gfx::Rect initial_bounds_; gfx::Rect initial_bounds;
// Location passed to the constructor, in |window->parent()|'s coordinates. // Location passed to the constructor, in |window->parent()|'s coordinates.
const gfx::Point initial_location_in_parent_; gfx::Point initial_location_in_parent;
// The component the user pressed on. // The component the user pressed on.
const int window_component_; int window_component;
// Bitmask of the |kBoundsChange_| constants. // Bitmask of the |kBoundsChange_| constants.
const int bounds_change_; int bounds_change;
// Bitmask of the |kBoundsChangeDirection_| constants. // Bitmask of the |kBoundsChangeDirection_| constants.
const int position_change_direction_; int position_change_direction;
// Bitmask of the |kBoundsChangeDirection_| constants. // Bitmask of the |kBoundsChangeDirection_| constants.
const int size_change_direction_; int size_change_direction;
// Will the drag actually modify the window? // Will the drag actually modify the window?
const bool is_resizable_; bool is_resizable;
// Size of the grid. // Size of the grid.
const int grid_size_; int grid_size;
};
static gfx::Rect CalculateBoundsForDrag(
const Details& details,
const gfx::Point& location);
static gfx::Rect AdjustBoundsToGrid(const Details& details);
static bool IsBottomEdge(int component);
// Set to true once Drag() is invoked and the bounds of the window change. private:
bool did_move_or_resize_; // Returns the new origin of the window. The arguments are the difference
// between the current location and the initial location.
static gfx::Point GetOriginForDrag(const Details& details,
int delta_x,
int delta_y);
internal::RootWindowEventFilter* root_filter_; // Returns the size of the window for the drag.
static gfx::Size GetSizeForDrag(const Details& details,
int* delta_x,
int* delta_y);
DISALLOW_COPY_AND_ASSIGN(WindowResizer); // Returns the width of the window.
static int GetWidthForDrag(const Details& details,
int min_width,
int* delta_x);
// Returns the height of the drag.
static int GetHeightForDrag(const Details& details,
int min_height,
int* delta_y);
}; };
} // namespace aura } // namespace aura
......
...@@ -93,8 +93,8 @@ WindowResizer* WorkspaceEventFilter::CreateWindowResizer( ...@@ -93,8 +93,8 @@ WindowResizer* WorkspaceEventFilter::CreateWindowResizer(
(window_component != HTCAPTION || GetTrackedByWorkspace(window))) { (window_component != HTCAPTION || GetTrackedByWorkspace(window))) {
return NULL; return NULL;
} }
return return WorkspaceWindowResizer::Create(
new WorkspaceWindowResizer(window, point, window_component, grid_size()); window, point, window_component, grid_size());
} }
void WorkspaceEventFilter::UpdateHoveredWindow( void WorkspaceEventFilter::UpdateHoveredWindow(
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/wm/workspace/workspace_window_resizer.h" #include "ash/wm/workspace/workspace_window_resizer.h"
#include "ash/shell.h"
#include "ash/wm/root_window_event_filter.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
...@@ -25,74 +27,123 @@ const aura::WindowProperty<int> kHeightBeforeObscuredProp = {0}; ...@@ -25,74 +27,123 @@ const aura::WindowProperty<int> kHeightBeforeObscuredProp = {0};
const aura::WindowProperty<int>* const kHeightBeforeObscuredKey = const aura::WindowProperty<int>* const kHeightBeforeObscuredKey =
&kHeightBeforeObscuredProp; &kHeightBeforeObscuredProp;
} // namespace void SetHeightBeforeObscured(aura::Window* window, int height) {
window->SetProperty(kHeightBeforeObscuredKey, height);
}
WorkspaceWindowResizer::WorkspaceWindowResizer(aura::Window* window, int GetHeightBeforeObscured(aura::Window* window) {
const gfx::Point& location, return window->GetProperty(kHeightBeforeObscuredKey);
int window_component,
int grid_size)
: WindowResizer(window, location, window_component, grid_size),
constrain_size_(wm::IsWindowNormal(window)) {
if (is_resizable() && GetHeightBeforeObscured(window) &&
constrain_size_ &&
(!WindowTouchesBottomOfScreen() ||
bounds_change() != kBoundsChange_Repositions)) {
ClearHeightBeforeObscured(window);
}
} }
void ClearHeightBeforeObscured(aura::Window* window) {
window->SetProperty(kHeightBeforeObscuredKey, 0);
}
} // namespace
WorkspaceWindowResizer::~WorkspaceWindowResizer() { WorkspaceWindowResizer::~WorkspaceWindowResizer() {
if (root_filter_)
root_filter_->UnlockCursor();
} }
gfx::Rect WorkspaceWindowResizer::GetBoundsForDrag(const gfx::Point& location) { // static
if (!is_resizable()) WorkspaceWindowResizer* WorkspaceWindowResizer::Create(
return WindowResizer::GetBoundsForDrag(location); aura::Window* window,
const gfx::Point& location,
int window_component,
int grid_size) {
Details details(window, location, window_component, grid_size);
return details.is_resizable ?
new WorkspaceWindowResizer(details) : NULL;
}
gfx::Rect bounds(WindowResizer::GetBoundsForDrag(location)); void WorkspaceWindowResizer::Drag(const gfx::Point& location) {
AdjustBounds(&bounds); gfx::Rect bounds = CalculateBoundsForDrag(details_, location);
return bounds; if (constrain_size_)
AdjustBoundsForMainWindow(&bounds);
if (bounds != details_.window->bounds()) {
did_move_or_resize_ = true;
details_.window->SetBounds(bounds);
}
} }
gfx::Rect WorkspaceWindowResizer::GetFinalBounds() { void WorkspaceWindowResizer::CompleteDrag() {
if (grid_size() <= 1 || !GetHeightBeforeObscured(window())) if (details_.grid_size <= 1 || !did_move_or_resize_ ||
return WindowResizer::GetFinalBounds(); details_.window_component != HTCAPTION)
return;
gfx::Rect bounds(AdjustBoundsToGrid(details_));
if (GetHeightBeforeObscured(window()) || constrain_size_) {
// Two things can happen:
// . We'll snap to the grid, which may result in different bounds. When
// dragging we only snap on release.
// . If the bounds are different, and the windows height was truncated
// because it touched the bottom, than snapping to the grid may cause the
// window to no longer touch the bottom. Push it back up.
gfx::Rect initial_bounds(window()->bounds()); gfx::Rect initial_bounds(window()->bounds());
bool at_bottom = WindowTouchesBottomOfScreen(); bool at_bottom = TouchesBottomOfScreen();
gfx::Rect bounds(WindowResizer::GetFinalBounds());
if (at_bottom && bounds.y() != initial_bounds.y()) { if (at_bottom && bounds.y() != initial_bounds.y()) {
if (bounds.y() < initial_bounds.y()) { if (bounds.y() < initial_bounds.y()) {
bounds.set_height(bounds.height() + grid_size() - bounds.set_height(bounds.height() + details_.grid_size -
(initial_bounds.y() - bounds.y())); (initial_bounds.y() - bounds.y()));
} }
AdjustBounds(&bounds); AdjustBoundsForMainWindow(&bounds);
}
} }
return bounds;
}
// static if (bounds == details_.window->bounds())
void WorkspaceWindowResizer::SetHeightBeforeObscured(aura::Window* window, return;
int height) {
window->SetProperty(kHeightBeforeObscuredKey, height);
}
// static if (bounds.size() != details_.window->bounds().size()) {
void WorkspaceWindowResizer::ClearHeightBeforeObscured(aura::Window* window) { // Don't attempt to animate a size change.
window->SetProperty(kHeightBeforeObscuredKey, 0); details_.window->SetBounds(bounds);
} return;
}
// static ui::ScopedLayerAnimationSettings scoped_setter(
int WorkspaceWindowResizer::GetHeightBeforeObscured(aura::Window* window) { details_.window->layer()->GetAnimator());
return window->GetProperty(kHeightBeforeObscuredKey); // Use a small duration since the grid is small.
scoped_setter.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
details_.window->SetBounds(bounds);
} }
void WorkspaceWindowResizer::AdjustBounds(gfx::Rect* bounds) const { void WorkspaceWindowResizer::RevertDrag() {
if (!constrain_size_) if (!did_move_or_resize_)
return; return;
details_.window->SetBounds(details_.initial_bounds);
}
WorkspaceWindowResizer::WorkspaceWindowResizer(
const Details& details)
: details_(details),
constrain_size_(wm::IsWindowNormal(details.window)),
did_move_or_resize_(false),
root_filter_(NULL) {
DCHECK(details_.is_resizable);
root_filter_ = Shell::GetInstance()->root_filter();
if (root_filter_)
root_filter_->LockCursor();
if (is_resizable() && constrain_size_ &&
(!TouchesBottomOfScreen() ||
details_.bounds_change != kBoundsChange_Repositions)) {
ClearCachedHeights();
}
}
void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
gfx::Rect* bounds) const {
gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window()));
AdjustBoundsForWindow(work_area, window(), bounds);
}
void WorkspaceWindowResizer::AdjustBoundsForWindow(
const gfx::Rect& work_area,
aura::Window* window,
gfx::Rect* bounds) const {
if (bounds->bottom() < work_area.bottom()) { if (bounds->bottom() < work_area.bottom()) {
int height = GetHeightBeforeObscured(window()); int height = GetHeightBeforeObscured(window);
if (!height) if (!height)
return; return;
height = std::max(bounds->height(), height); height = std::max(bounds->height(), height);
...@@ -103,20 +154,26 @@ void WorkspaceWindowResizer::AdjustBounds(gfx::Rect* bounds) const { ...@@ -103,20 +154,26 @@ void WorkspaceWindowResizer::AdjustBounds(gfx::Rect* bounds) const {
if (bounds->bottom() == work_area.bottom()) if (bounds->bottom() == work_area.bottom())
return; return;
if (!GetHeightBeforeObscured(window())) if (!GetHeightBeforeObscured(window))
SetHeightBeforeObscured(window(), window()->bounds().height()); SetHeightBeforeObscured(window, window->bounds().height());
gfx::Size min_size = window()->delegate()->GetMinimumSize(); gfx::Size min_size = window->delegate()->GetMinimumSize();
bounds->set_height(std::max(0, work_area.bottom() - bounds->y())); bounds->set_height(
std::max(0, work_area.bottom() - bounds->y()));
if (bounds->height() < min_size.height()) { if (bounds->height() < min_size.height()) {
bounds->set_height(min_size.height()); bounds->set_height(min_size.height());
bounds->set_y(work_area.bottom() - min_size.height()); bounds->set_y(work_area.bottom() - min_size.height());
} }
} }
bool WorkspaceWindowResizer::WindowTouchesBottomOfScreen() const { void WorkspaceWindowResizer::ClearCachedHeights() {
gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); ClearHeightBeforeObscured(details_.window);
return window()->bounds().bottom() == work_area.bottom(); }
bool WorkspaceWindowResizer::TouchesBottomOfScreen() const {
gfx::Rect work_area(
gfx::Screen::GetMonitorWorkAreaNearestWindow(details_.window));
return details_.window->bounds().bottom() == work_area.bottom();
} }
} // namespace internal } // namespace internal
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
namespace ash { namespace ash {
namespace internal { namespace internal {
class RootWindowEventFilter;
// WindowResizer implementation for workspaces. This enforces that windows are // WindowResizer implementation for workspaces. This enforces that windows are
// not allowed to vertically move or resize outside of the work area. As windows // not allowed to vertically move or resize outside of the work area. As windows
// are moved outside the work area they are shrunk. We remember the height of // are moved outside the work area they are shrunk. We remember the height of
...@@ -19,33 +21,56 @@ namespace internal { ...@@ -19,33 +21,56 @@ namespace internal {
// attempt to restore the old height. // attempt to restore the old height.
class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
public: public:
WorkspaceWindowResizer(aura::Window* window, virtual ~WorkspaceWindowResizer();
// Creates a new WorkspaceWindowResizer. The caller takes ownership of the
// returned object. Returns NULL if not resizable.
static WorkspaceWindowResizer* Create(
aura::Window* window,
const gfx::Point& location, const gfx::Point& location,
int window_component, int window_component,
int grid_size); int grid_size);
virtual ~WorkspaceWindowResizer();
protected: // Returns true if the drag will result in changing the window in anyway.
// WindowResizer overrides: bool is_resizable() const { return details_.is_resizable; }
virtual gfx::Rect GetBoundsForDrag(const gfx::Point& location) OVERRIDE;
virtual gfx::Rect GetFinalBounds() OVERRIDE; const gfx::Point& initial_location_in_parent() const {
return details_.initial_location_in_parent;
}
// Overridden from WindowResizer:
virtual void Drag(const gfx::Point& location);
virtual void CompleteDrag();
virtual void RevertDrag();
private: private:
// Used to maintain the height of the window before we started collapsing it. explicit WorkspaceWindowResizer(const Details& details);
static void SetHeightBeforeObscured(aura::Window* window, int height);
static void ClearHeightBeforeObscured(aura::Window* window);
static int GetHeightBeforeObscured(aura::Window* window);
// Adjusts the bounds to enforce that windows are vertically contained in the // Adjusts the bounds to enforce that windows are vertically contained in the
// work area. // work area.
void AdjustBounds(gfx::Rect* bounds) const; void AdjustBoundsForMainWindow(gfx::Rect* bounds) const;
void AdjustBoundsForWindow(const gfx::Rect& work_area,
aura::Window* window,
gfx::Rect* bounds) const;
// Clears the cached height of the window being dragged.
void ClearCachedHeights();
// Returns true if the window touches the bottom of the work area. // Returns true if the window touches the bottom of the work area.
bool WindowTouchesBottomOfScreen() const; bool TouchesBottomOfScreen() const;
aura::Window* window() const { return details_.window; }
const Details details_;
// True if the window size (height) should be constrained. // True if the window size (height) should be constrained.
const bool constrain_size_; const bool constrain_size_;
// Set to true once Drag() is invoked and the bounds of the window change.
bool did_move_or_resize_;
internal::RootWindowEventFilter* root_filter_;
DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer);
}; };
......
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