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

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: fix browser tests 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
« no previous file with comments | « no previous file | apps/shell_window_geometry_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
125 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 127 gfx::Display display = screen->GetDisplayMatching(cached_bounds);
126 gfx::Display display = screen->GetDisplayMatching(cached_bounds); 128 gfx::Rect current_screen_bounds = display.work_area();
127 gfx::Rect current_screen_bounds = display.work_area(); 129 AdjustBoundsToBeVisibleOnScreen(cached_bounds,
128 AdjustBoundsToBeVisibleOnScreen(cached_bounds, 130 cached_screen_bounds,
129 cached_screen_bounds, 131 current_screen_bounds,
130 current_screen_bounds, 132 params.minimum_size,
131 params.minimum_size, 133 &bounds);
132 &bounds); 134 new_params.state = cached_state;
133 }
134 } 135 }
135 } 136 }
136 137
137 CreateParams new_params = params;
138
139 gfx::Size& minimum_size = new_params.minimum_size; 138 gfx::Size& minimum_size = new_params.minimum_size;
140 gfx::Size& maximum_size = new_params.maximum_size; 139 gfx::Size& maximum_size = new_params.maximum_size;
141 140
142 // In the case that minimum size > maximum size, we consider the minimum 141 // In the case that minimum size > maximum size, we consider the minimum
143 // size to be more important. 142 // size to be more important.
144 if (maximum_size.width() && maximum_size.width() < minimum_size.width()) 143 if (maximum_size.width() && maximum_size.width() < minimum_size.width())
145 maximum_size.set_width(minimum_size.width()); 144 maximum_size.set_width(minimum_size.width());
146 if (maximum_size.height() && maximum_size.height() < minimum_size.height()) 145 if (maximum_size.height() && maximum_size.height() < minimum_size.height())
147 maximum_size.set_height(minimum_size.height()); 146 maximum_size.set_height(minimum_size.height());
148 147
149 if (maximum_size.width() && bounds.width() > maximum_size.width()) 148 if (maximum_size.width() && bounds.width() > maximum_size.width())
150 bounds.set_width(maximum_size.width()); 149 bounds.set_width(maximum_size.width());
151 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) 150 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width())
152 bounds.set_width(minimum_size.width()); 151 bounds.set_width(minimum_size.width());
153 152
154 if (maximum_size.height() && bounds.height() > maximum_size.height()) 153 if (maximum_size.height() && bounds.height() > maximum_size.height())
155 bounds.set_height(maximum_size.height()); 154 bounds.set_height(maximum_size.height());
156 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) 155 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height())
157 bounds.set_height(minimum_size.height()); 156 bounds.set_height(minimum_size.height());
158 157
159 new_params.bounds = bounds; 158 new_params.bounds = bounds;
160 159
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)); 160 native_app_window_.reset(NativeAppWindow::Create(this, new_params));
165 161
166 if (!new_params.hidden) { 162 if (!new_params.hidden) {
167 if (window_type_is_panel()) 163 if (window_type_is_panel())
168 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. 164 GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
169 else 165 else
170 GetBaseWindow()->Show(); 166 GetBaseWindow()->Show();
171 } 167 }
172 168
173 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) 169 if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 screen_bounds, 578 screen_bounds,
583 window_state); 579 window_state);
584 } 580 }
585 581
586 void ShellWindow::AdjustBoundsToBeVisibleOnScreen( 582 void ShellWindow::AdjustBoundsToBeVisibleOnScreen(
587 const gfx::Rect& cached_bounds, 583 const gfx::Rect& cached_bounds,
588 const gfx::Rect& cached_screen_bounds, 584 const gfx::Rect& cached_screen_bounds,
589 const gfx::Rect& current_screen_bounds, 585 const gfx::Rect& current_screen_bounds,
590 const gfx::Size& minimum_size, 586 const gfx::Size& minimum_size,
591 gfx::Rect* bounds) const { 587 gfx::Rect* bounds) const {
592 if (!bounds)
593 return;
594
595 *bounds = cached_bounds; 588 *bounds = cached_bounds;
596 589
597 // Reposition and resize the bounds if the cached_screen_bounds is different 590 // 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 591 // from the current screen bounds and the current screen bounds doesn't
599 // completely contain the bounds. 592 // completely contain the bounds.
600 if (!cached_screen_bounds.IsEmpty() && 593 if (cached_screen_bounds != current_screen_bounds &&
601 cached_screen_bounds != current_screen_bounds &&
602 !current_screen_bounds.Contains(cached_bounds)) { 594 !current_screen_bounds.Contains(cached_bounds)) {
603 bounds->set_width( 595 bounds->set_width(
604 std::max(minimum_size.width(), 596 std::max(minimum_size.width(),
605 std::min(bounds->width(), current_screen_bounds.width()))); 597 std::min(bounds->width(), current_screen_bounds.width())));
606 bounds->set_height( 598 bounds->set_height(
607 std::max(minimum_size.height(), 599 std::max(minimum_size.height(),
608 std::min(bounds->height(), current_screen_bounds.height()))); 600 std::min(bounds->height(), current_screen_bounds.height())));
609 bounds->set_x( 601 bounds->set_x(
610 std::max(current_screen_bounds.x(), 602 std::max(current_screen_bounds.x(),
611 std::min(bounds->x(), 603 std::min(bounds->x(),
(...skipping 17 matching lines...) Expand all
629 region.bounds.x(), 621 region.bounds.x(),
630 region.bounds.y(), 622 region.bounds.y(),
631 region.bounds.right(), 623 region.bounds.right(),
632 region.bounds.bottom(), 624 region.bounds.bottom(),
633 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 625 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
634 } 626 }
635 return sk_region; 627 return sk_region;
636 } 628 }
637 629
638 } // namespace apps 630 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | apps/shell_window_geometry_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698