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

Side by Side Diff: ash/wm/dock/docked_window_layout_manager.cc

Issue 172243005: Prevents crash when docking a detached panel while fullscreen window is active (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Prevents crash when docking a detached panel while fullscreen window is active Created 6 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/dock/docked_window_layout_manager.h" 5 #include "ash/wm/dock/docked_window_layout_manager.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shelf/shelf.h" 9 #include "ash/shelf/shelf.h"
10 #include "ash/shelf/shelf_constants.h" 10 #include "ash/shelf/shelf_constants.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 GetWindowHeightCloseTo(win2.window(), 0); 294 GetWindowHeightCloseTo(win2.window(), 0);
295 } 295 }
296 }; 296 };
297 297
298 // A functor used to sort the windows in order of their center Y position. 298 // A functor used to sort the windows in order of their center Y position.
299 // |delta| is a pre-calculated distance from the bottom of one window to the top 299 // |delta| is a pre-calculated distance from the bottom of one window to the top
300 // of the next. Its value can be positive (gap) or negative (overlap). 300 // of the next. Its value can be positive (gap) or negative (overlap).
301 // Half of |delta| is used as a transition point at which windows could ideally 301 // Half of |delta| is used as a transition point at which windows could ideally
302 // swap positions. 302 // swap positions.
303 struct CompareWindowPos { 303 struct CompareWindowPos {
304 CompareWindowPos(aura::Window* dragged_window, float delta) 304 CompareWindowPos(aura::Window* dragged_window,
305 aura::Window* docked_container,
306 float delta)
305 : dragged_window_(dragged_window), 307 : dragged_window_(dragged_window),
308 docked_container_(docked_container),
306 delta_(delta / 2) {} 309 delta_(delta / 2) {}
307 310
308 bool operator()(WindowWithHeight window_with_height1, 311 bool operator()(WindowWithHeight window_with_height1,
309 WindowWithHeight window_with_height2) { 312 WindowWithHeight window_with_height2) {
310 // Use target coordinates since animations may be active when windows are 313 // Use target coordinates since animations may be active when windows are
311 // reordered. 314 // reordered.
312 aura::Window* win1(window_with_height1.window()); 315 aura::Window* win1(window_with_height1.window());
313 aura::Window* win2(window_with_height2.window()); 316 aura::Window* win2(window_with_height2.window());
314 gfx::Rect win1_bounds = ScreenUtil::ConvertRectToScreen( 317 gfx::Rect win1_bounds = ScreenUtil::ConvertRectToScreen(
315 win1->parent(), win1->GetTargetBounds()); 318 docked_container_, win1->GetTargetBounds());
316 gfx::Rect win2_bounds = ScreenUtil::ConvertRectToScreen( 319 gfx::Rect win2_bounds = ScreenUtil::ConvertRectToScreen(
317 win2->parent(), win2->GetTargetBounds()); 320 docked_container_, win2->GetTargetBounds());
318 win1_bounds.set_height(window_with_height1.height_); 321 win1_bounds.set_height(window_with_height1.height_);
319 win2_bounds.set_height(window_with_height2.height_); 322 win2_bounds.set_height(window_with_height2.height_);
320 // If one of the windows is the |dragged_window_| attempt to make an 323 // If one of the windows is the |dragged_window_| attempt to make an
321 // earlier swap between the windows than just based on their centers. 324 // earlier swap between the windows than just based on their centers.
322 // This is possible if the dragged window is at least as tall as the other 325 // This is possible if the dragged window is at least as tall as the other
323 // window. 326 // window.
324 if (win1 == dragged_window_) 327 if (win1 == dragged_window_)
325 return compare_two_windows(win1_bounds, win2_bounds); 328 return compare_two_windows(win1_bounds, win2_bounds);
326 if (win2 == dragged_window_) 329 if (win2 == dragged_window_)
327 return !compare_two_windows(win2_bounds, win1_bounds); 330 return !compare_two_windows(win2_bounds, win1_bounds);
(...skipping 19 matching lines...) Expand all
347 if (result1 != result2) 350 if (result1 != result2)
348 return result1; 351 return result1;
349 352
350 // Otherwise it is not possible to be sure that the windows will not bounce. 353 // Otherwise it is not possible to be sure that the windows will not bounce.
351 // In this case just compare the centers. 354 // In this case just compare the centers.
352 return bounds1.CenterPoint().y() < bounds2.CenterPoint().y(); 355 return bounds1.CenterPoint().y() < bounds2.CenterPoint().y();
353 } 356 }
354 357
355 private: 358 private:
356 aura::Window* dragged_window_; 359 aura::Window* dragged_window_;
360 aura::Window* docked_container_;
357 float delta_; 361 float delta_;
358 }; 362 };
359 363
360 } // namespace 364 } // namespace
361 365
362 //////////////////////////////////////////////////////////////////////////////// 366 ////////////////////////////////////////////////////////////////////////////////
363 // A class that observes shelf for bounds changes. 367 // A class that observes shelf for bounds changes.
364 class DockedWindowLayoutManager::ShelfWindowObserver : public WindowObserver { 368 class DockedWindowLayoutManager::ShelfWindowObserver : public WindowObserver {
365 public: 369 public:
366 explicit ShelfWindowObserver( 370 explicit ShelfWindowObserver(
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 if (visible_windows->empty() || 1152 if (visible_windows->empty() ||
1149 (visible_windows->size() == 1 && 1153 (visible_windows->size() == 1 &&
1150 (*visible_windows)[0].window() == dragged_window_)) { 1154 (*visible_windows)[0].window() == dragged_window_)) {
1151 new_width = 0; 1155 new_width = 0;
1152 } 1156 }
1153 UpdateDockedWidth(new_width); 1157 UpdateDockedWidth(new_width);
1154 // Sort windows by their center positions and fan out overlapping 1158 // Sort windows by their center positions and fan out overlapping
1155 // windows. 1159 // windows.
1156 std::sort(visible_windows->begin(), visible_windows->end(), 1160 std::sort(visible_windows->begin(), visible_windows->end(),
1157 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL, 1161 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL,
1162 dock_container_,
1158 delta)); 1163 delta));
1159 for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin(); 1164 for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin();
1160 iter != visible_windows->end(); ++iter) { 1165 iter != visible_windows->end(); ++iter) {
1161 aura::Window* window = iter->window(); 1166 aura::Window* window = iter->window();
1162 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen( 1167 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen(
1163 window->parent(), window->GetTargetBounds()); 1168 dock_container_, window->GetTargetBounds());
1164 // A window is extended or shrunk to be as close as possible to the ideal 1169 // A window is extended or shrunk to be as close as possible to the ideal
1165 // docked area width. Windows that were resized by a user are kept at their 1170 // docked area width. Windows that were resized by a user are kept at their
1166 // existing size. 1171 // existing size.
1167 // This also enforces the min / max restrictions on the docked area width. 1172 // This also enforces the min / max restrictions on the docked area width.
1168 bounds.set_width(GetWindowWidthCloseTo( 1173 bounds.set_width(GetWindowWidthCloseTo(
1169 window, 1174 window,
1170 wm::GetWindowState(window)->bounds_changed_by_user() ? 1175 wm::GetWindowState(window)->bounds_changed_by_user() ?
1171 bounds.width() : ideal_docked_width)); 1176 bounds.width() : ideal_docked_width));
1172 DCHECK_LE(bounds.width(), ideal_docked_width); 1177 DCHECK_LE(bounds.width(), ideal_docked_width);
1173 1178
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( 1311 void DockedWindowLayoutManager::OnKeyboardBoundsChanging(
1307 const gfx::Rect& keyboard_bounds) { 1312 const gfx::Rect& keyboard_bounds) {
1308 // This bounds change will have caused a change to the Shelf which does not 1313 // This bounds change will have caused a change to the Shelf which does not
1309 // propagate automatically to this class, so manually recalculate bounds. 1314 // propagate automatically to this class, so manually recalculate bounds.
1310 Relayout(); 1315 Relayout();
1311 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); 1316 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING);
1312 } 1317 }
1313 1318
1314 } // namespace internal 1319 } // namespace internal
1315 } // namespace ash 1320 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698