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

Unified Diff: ash/wm/dock/docked_window_layout_manager.cc

Issue 23431009: Windows docking should get triggered by pressing against the screen edge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows docking should get triggered by pressing against the screen edge Created 7 years, 3 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: ash/wm/dock/docked_window_layout_manager.cc
diff --git a/ash/wm/dock/docked_window_layout_manager.cc b/ash/wm/dock/docked_window_layout_manager.cc
index 36998df309179e3113ec83e016e32ce7f570c16a..81bab074e0b203574abd50097294e8fcbc3b218e 100644
--- a/ash/wm/dock/docked_window_layout_manager.cc
+++ b/ash/wm/dock/docked_window_layout_manager.cc
@@ -28,8 +28,9 @@ namespace internal {
// Minimum, maximum width of the dock area and a width of the gap
const int DockedWindowLayoutManager::kMinDockWidth = 200;
-const int DockedWindowLayoutManager::kMaxDockWidth = 450;
+const int DockedWindowLayoutManager::kMaxDockWidth = 360;
const int DockedWindowLayoutManager::kMinDockGap = 2;
+const int kMaxVerticalPercentage = 90;
flackr 2013/09/06 02:18:43 Just to simplify this CL, adding the max vertical
varkha 2013/09/09 15:38:42 Done.
const int kWindowIdealSpacing = 4;
namespace {
@@ -193,6 +194,7 @@ void DockedWindowLayoutManager::StartDragging(aura::Window* window) {
dragged_window_ = window;
// Start observing a window unless it is docked container's child in which
// case it is already observed.
+ LOG(INFO) << "start dragging " << window;
if (dragged_window_->parent() != dock_container_)
dragged_window_->AddObserver(this);
is_dragged_from_dock_ = window->parent() == dock_container_;
@@ -207,6 +209,7 @@ void DockedWindowLayoutManager::DockDraggedWindow(aura::Window* window) {
void DockedWindowLayoutManager::UndockDraggedWindow() {
OnWindowUndocked();
Relayout();
+ UpdateDockBounds();
is_dragged_from_dock_ = false;
}
@@ -215,11 +218,16 @@ void DockedWindowLayoutManager::FinishDragging() {
if (is_dragged_window_docked_)
OnWindowUndocked();
DCHECK (!is_dragged_window_docked_);
+ LOG(INFO) << "finish dragging " << dragged_window_;
// Stop observing a window unless it is docked container's child in which
// case it needs to keep being observed after the drag completes.
- if (dragged_window_->parent() != dock_container_)
+ if (dragged_window_->parent() != dock_container_) {
dragged_window_->RemoveObserver(this);
+ if (last_active_window_ == dragged_window_)
+ last_active_window_ = NULL;
+ }
dragged_window_ = NULL;
+ dragged_bounds_ = gfx::Rect();
Relayout();
UpdateDockBounds();
}
@@ -239,26 +247,20 @@ void DockedWindowLayoutManager::SetLauncher(ash::Launcher* launcher) {
DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow(
const aura::Window* window) const {
const gfx::Rect& bounds(window->GetBoundsInScreen());
- const gfx::Rect docked_bounds = dock_container_->GetBoundsInScreen();
-
- // Do not allow docking if a window is vertically maximized (as is the case
- // when it is snapped).
- const gfx::Rect work_area =
- Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).work_area();
- if (bounds.y() == work_area.y() && bounds.height() == work_area.height())
- return DOCKED_ALIGNMENT_NONE;
- // Do not allow docking on the same side as launcher shelf.
- ShelfAlignment shelf_alignment = SHELF_ALIGNMENT_BOTTOM;
- if (launcher_)
- shelf_alignment = launcher_->alignment();
+ // Test overlap with an existing docked area first.
+ if (docked_bounds_.Intersects(bounds) &&
+ alignment_ != DOCKED_ALIGNMENT_NONE) {
+ // A window is being added to other docked windows (on the same side).
+ return alignment_;
+ }
- if (bounds.x() == docked_bounds.x() &&
- shelf_alignment != SHELF_ALIGNMENT_LEFT) {
+ const gfx::Rect container_bounds = dock_container_->GetBoundsInScreen();
+ if (bounds.x() <= container_bounds.x() &&
+ bounds.right() > container_bounds.x()) {
return DOCKED_ALIGNMENT_LEFT;
- }
- if (bounds.right() == docked_bounds.right() &&
- shelf_alignment != SHELF_ALIGNMENT_RIGHT) {
+ } else if (bounds.x() < container_bounds.right() &&
+ bounds.right() >= container_bounds.right()) {
return DOCKED_ALIGNMENT_RIGHT;
}
return DOCKED_ALIGNMENT_NONE;
@@ -293,6 +295,7 @@ void DockedWindowLayoutManager::OnWindowResized() {
void DockedWindowLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
if (child->type() == aura::client::WINDOW_TYPE_POPUP)
return;
+ LOG(INFO) << "added " << child;
// Dragged windows are already observed by StartDragging and do not change
// docked alignment during the drag.
if (child == dragged_window_)
@@ -310,6 +313,7 @@ void DockedWindowLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
if (child->type() == aura::client::WINDOW_TYPE_POPUP)
return;
+ LOG(INFO) << "removed " << child;
// Dragged windows are stopped being observed by FinishDragging and do not
// change alignment during the drag. They also cannot be set to be the
// |last_active_window_|.
@@ -400,6 +404,7 @@ void DockedWindowLayoutManager::OnWindowBoundsChanged(
}
void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) {
+ LOG(INFO) << "destroying " << window;
if (dragged_window_ == window) {
FinishDragging();
DCHECK(!dragged_window_);
@@ -475,6 +480,7 @@ void DockedWindowLayoutManager::RestoreWindow(aura::Window* window) {
}
void DockedWindowLayoutManager::OnWindowDocked(aura::Window* window) {
+ LOG(INFO) << "docked";
DCHECK(!is_dragged_window_docked_);
is_dragged_window_docked_ = true;
@@ -484,6 +490,7 @@ void DockedWindowLayoutManager::OnWindowDocked(aura::Window* window) {
}
void DockedWindowLayoutManager::OnWindowUndocked() {
+ LOG(INFO) << "undocked";
// If this is the first window getting docked - update alignment.
if (!IsAnyWindowDocked())
alignment_ = GetAlignmentOfWindow(dragged_window_);
@@ -544,7 +551,10 @@ void DockedWindowLayoutManager::Relayout() {
int available_room = work_area.height();
for (aura::Window::Windows::const_iterator iter = visible_windows.begin();
iter != visible_windows.end(); ++iter) {
- available_room -= (*iter)->bounds().height();
+ int height = (*iter)->bounds().height();
+ if (height == work_area.height())
flackr 2013/09/06 02:18:43 This allows the height to be greater than kMaxVert
varkha 2013/09/09 15:38:42 This was intentional to target vertically maximize
+ height = work_area.height() * kMaxVerticalPercentage / 100;
+ available_room -= height;
}
const int num_windows = visible_windows.size();
const float delta = (float)available_room /
@@ -564,6 +574,20 @@ void DockedWindowLayoutManager::Relayout() {
aura::Window* window = *iter;
gfx::Rect bounds = window->GetBoundsInScreen();
+ DockedAlignment alignment = alignment_;
+ if (alignment == DOCKED_ALIGNMENT_NONE && window == dragged_window_) {
+ alignment = GetAlignmentOfWindow(window);
+ if (alignment == DOCKED_ALIGNMENT_NONE)
+ bounds.set_size(gfx::Size());
+ }
+
+ // Restrict width.
+ if (bounds.width() > kMaxDockWidth)
+ bounds.set_width(kMaxDockWidth);
+ // Shrink height of vertically maximized windows to kMaxVerticalPercentage.
+ if (bounds.height() == work_area.height())
+ bounds.set_height(work_area.height() * kMaxVerticalPercentage / 100);
+
// Fan out windows evenly distributing the overlap or remaining free space.
bounds.set_y(std::max(work_area.y(),
std::min(work_area.bottom() - bounds.height(),
@@ -572,7 +596,7 @@ void DockedWindowLayoutManager::Relayout() {
// All docked windows other than the one currently dragged remain stuck
// to the screen edge.
- switch (alignment_) {
+ switch (alignment) {
case DOCKED_ALIGNMENT_LEFT:
bounds.set_x(dock_bounds.x());
break;
@@ -586,6 +610,8 @@ void DockedWindowLayoutManager::Relayout() {
dragged_bounds_ = bounds;
continue;
}
+ // If the following asserts it is probably because not all the children
+ // have been removed when dock was closed.
DCHECK_NE(alignment_, DOCKED_ALIGNMENT_NONE);
// Keep the dock at least kMinDockWidth when all windows in it overhang.
docked_width_ = std::min(kMaxDockWidth,

Powered by Google App Engine
This is Rietveld 408576698