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

Side by Side Diff: apps/shell_window.cc

Issue 21444002: Do not restore corrupt cached app window bounds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "apps/shell_window.h" 5 #include "apps/shell_window.h"
6 6
7 #include "apps/shell_window_geometry_cache.h" 7 #include "apps/shell_window_geometry_cache.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 gfx::Rect bounds = params.bounds; 101 gfx::Rect bounds = params.bounds;
102 102
103 if (bounds.width() == 0) 103 if (bounds.width() == 0)
104 bounds.set_width(kDefaultWidth); 104 bounds.set_width(kDefaultWidth);
105 if (bounds.height() == 0) 105 if (bounds.height() == 0)
106 bounds.set_height(kDefaultHeight); 106 bounds.set_height(kDefaultHeight);
107 107
108 // If left and top are left undefined, the native shell window will center 108 // If left and top are left undefined, the native shell window will center
109 // the window on the main screen in a platform-defined manner. 109 // the window on the main screen in a platform-defined manner.
110 110
111 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; 111 CreateParams new_params = params;
112
113 // Load cached state if it exists.
112 if (!params.window_key.empty()) { 114 if (!params.window_key.empty()) {
113 window_key_ = params.window_key; 115 window_key_ = params.window_key;
114 116
115 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); 117 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile());
116 118
117 gfx::Rect cached_bounds; 119 gfx::Rect cached_bounds;
118 gfx::Rect cached_screen_bounds; 120 gfx::Rect cached_screen_bounds;
121 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
119 if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds, 122 if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds,
120 &cached_screen_bounds, &cached_state)) { 123 &cached_screen_bounds, &cached_state)) {
121 bounds = cached_bounds;
122 // App window has cached screen bounds, make sure it fits on screen in 124 // App window has cached screen bounds, make sure it fits on screen in
123 // case the screen resolution changed. 125 // case the screen resolution changed.
124 if (!cached_screen_bounds.IsEmpty()) { 126 AdjustBoundsToBeVisibleOnScreen(cached_bounds,
125 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 127 cached_screen_bounds,
126 gfx::Display display = screen->GetDisplayMatching(cached_bounds); 128 params.minimum_size,
127 gfx::Rect current_screen_bounds = display.work_area(); 129 &bounds);
128 AdjustBoundsToBeVisibleOnScreen(cached_bounds, 130 new_params.state = cached_state;
129 cached_screen_bounds,
130 current_screen_bounds,
131 params.minimum_size,
132 &bounds);
133 }
134 } 131 }
135 } 132 }
136 133
137 CreateParams new_params = params;
138
139 gfx::Size& minimum_size = new_params.minimum_size; 134 gfx::Size& minimum_size = new_params.minimum_size;
140 gfx::Size& maximum_size = new_params.maximum_size; 135 gfx::Size& maximum_size = new_params.maximum_size;
141 136
142 // In the case that minimum size > maximum size, we consider the minimum 137 // In the case that minimum size > maximum size, we consider the minimum
143 // size to be more important. 138 // size to be more important.
144 if (maximum_size.width() && maximum_size.width() < minimum_size.width()) 139 if (maximum_size.width() && maximum_size.width() < minimum_size.width())
145 maximum_size.set_width(minimum_size.width()); 140 maximum_size.set_width(minimum_size.width());
146 if (maximum_size.height() && maximum_size.height() < minimum_size.height()) 141 if (maximum_size.height() && maximum_size.height() < minimum_size.height())
147 maximum_size.set_height(minimum_size.height()); 142 maximum_size.set_height(minimum_size.height());
148 143
149 if (maximum_size.width() && bounds.width() > maximum_size.width()) 144 if (maximum_size.width() && bounds.width() > maximum_size.width())
150 bounds.set_width(maximum_size.width()); 145 bounds.set_width(maximum_size.width());
151 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) 146 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width())
152 bounds.set_width(minimum_size.width()); 147 bounds.set_width(minimum_size.width());
153 148
154 if (maximum_size.height() && bounds.height() > maximum_size.height()) 149 if (maximum_size.height() && bounds.height() > maximum_size.height())
155 bounds.set_height(maximum_size.height()); 150 bounds.set_height(maximum_size.height());
156 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) 151 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height())
157 bounds.set_height(minimum_size.height()); 152 bounds.set_height(minimum_size.height());
158 153
159 new_params.bounds = bounds; 154 new_params.bounds = bounds;
160 155
161 if (cached_state != ui::SHOW_STATE_DEFAULT)
162 new_params.state = cached_state;
163
164 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); 156 native_app_window_.reset(NativeAppWindow::Create(this, new_params));
165 157
166 if (!new_params.hidden) { 158 if (!new_params.hidden) {
167 if (window_type_is_panel()) 159 if (window_type_is_panel())
168 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. 160 GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
169 else 161 else
170 GetBaseWindow()->Show(); 162 GetBaseWindow()->Show();
171 } 163 }
172 164
173 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) 165 if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 cache->SaveGeometry(extension()->id(), 571 cache->SaveGeometry(extension()->id(),
580 window_key_, 572 window_key_,
581 bounds, 573 bounds,
582 screen_bounds, 574 screen_bounds,
583 window_state); 575 window_state);
584 } 576 }
585 577
586 void ShellWindow::AdjustBoundsToBeVisibleOnScreen( 578 void ShellWindow::AdjustBoundsToBeVisibleOnScreen(
587 const gfx::Rect& cached_bounds, 579 const gfx::Rect& cached_bounds,
588 const gfx::Rect& cached_screen_bounds, 580 const gfx::Rect& cached_screen_bounds,
589 const gfx::Rect& current_screen_bounds,
590 const gfx::Size& minimum_size, 581 const gfx::Size& minimum_size,
591 gfx::Rect* bounds) const { 582 gfx::Rect* bounds) const {
592 if (!bounds) 583 *bounds = cached_bounds;
593 return;
594 584
595 *bounds = cached_bounds; 585 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
586 gfx::Display display = screen->GetDisplayMatching(cached_bounds);
587 gfx::Rect current_screen_bounds = display.work_area();
596 588
597 // Reposition and resize the bounds if the cached_screen_bounds is different 589 // Reposition and resize the bounds if the cached_screen_bounds is different
598 // from the current screen bounds and the current screen bounds doesn't 590 // from the current screen bounds and the current screen bounds doesn't
599 // completely contain the bounds. 591 // completely contain the bounds.
600 if (!cached_screen_bounds.IsEmpty() && 592 if (cached_screen_bounds != current_screen_bounds &&
601 cached_screen_bounds != current_screen_bounds &&
602 !current_screen_bounds.Contains(cached_bounds)) { 593 !current_screen_bounds.Contains(cached_bounds)) {
603 bounds->set_width( 594 bounds->set_width(
604 std::max(minimum_size.width(), 595 std::max(minimum_size.width(),
605 std::min(bounds->width(), current_screen_bounds.width()))); 596 std::min(bounds->width(), current_screen_bounds.width())));
606 bounds->set_height( 597 bounds->set_height(
607 std::max(minimum_size.height(), 598 std::max(minimum_size.height(),
608 std::min(bounds->height(), current_screen_bounds.height()))); 599 std::min(bounds->height(), current_screen_bounds.height())));
609 bounds->set_x( 600 bounds->set_x(
610 std::max(current_screen_bounds.x(), 601 std::max(current_screen_bounds.x(),
611 std::min(bounds->x(), 602 std::min(bounds->x(),
(...skipping 17 matching lines...) Expand all
629 region.bounds.x(), 620 region.bounds.x(),
630 region.bounds.y(), 621 region.bounds.y(),
631 region.bounds.right(), 622 region.bounds.right(),
632 region.bounds.bottom(), 623 region.bounds.bottom(),
633 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 624 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
634 } 625 }
635 return sk_region; 626 return sk_region;
636 } 627 }
637 628
638 } // namespace apps 629 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698