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

Unified Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 17378003: [WIN]Save work area of window and adjust bounds to ensure it fit on screen before show. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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: chrome/browser/ui/extensions/shell_window.cc
diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc
index 6e30846329c6aed4fbd27f8be0c410d652b6c9fa..7290b57e5a8a9fa8d354081a1330d36cc00460bd 100644
--- a/chrome/browser/ui/extensions/shell_window.cc
+++ b/chrome/browser/ui/extensions/shell_window.cc
@@ -152,6 +152,7 @@ void ShellWindow::Init(const GURL& url,
// If left and top are left undefined, the native shell window will center
// the window on the main screen in a platform-defined manner.
+ gfx::Rect cached_work_area;
ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
if (!params.window_key.empty()) {
window_key_ = params.window_key;
@@ -161,7 +162,7 @@ void ShellWindow::Init(const GURL& url,
gfx::Rect cached_bounds;
if (cache->GetGeometry(extension()->id(), params.window_key,
- &cached_bounds, &cached_state)) {
+ &cached_bounds, &cached_work_area, &cached_state)) {
bounds = cached_bounds;
}
}
@@ -195,6 +196,14 @@ void ShellWindow::Init(const GURL& url,
native_app_window_.reset(NativeAppWindow::Create(this, new_params));
+ // App window has cached work area, make sure it fits on screen in case of the
scheib 2013/06/18 21:52:06 Why not place this above, before new_params.bounds
zhchbin 2013/06/19 05:43:32 Because in the AdjustBoundsToBeVisibleOnMonitorCon
+ // screen resolution changed before show.
+ if (!cached_work_area.IsEmpty()) {
+ gfx::Rect new_bounds;
+ AdjustBoundsToBeVisibleOnMonitorContaining(bounds, cached_work_area,
+ &new_bounds);
+ native_app_window_->SetBounds(new_bounds);
+ }
if (!new_params.hidden) {
if (window_type_is_panel())
GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
@@ -617,10 +626,45 @@ void ShellWindow::SaveWindowPosition() {
gfx::Rect bounds = native_app_window_->GetRestoredBounds();
bounds.Inset(native_app_window_->GetFrameInsets());
+ gfx::Rect work_area = native_app_window_->GetWindowWorkArea();
ui::WindowShowState window_state = native_app_window_->GetRestoredState();
- cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state);
+ cache->SaveGeometry(extension()->id(),
+ window_key_,
+ bounds,
+ work_area,
+ window_state);
}
+void ShellWindow::AdjustBoundsToBeVisibleOnMonitorContaining(
scheib 2013/06/18 21:52:06 Monitor is inconsistent with naming elsewhere. 'Wo
scheib 2013/06/18 21:52:06 Please add several tests for this function, for sh
zhchbin 2013/06/20 06:35:50 Done.
zhchbin 2013/06/20 06:35:50 Done.
+ const gfx::Rect& cached_bounds,
+ const gfx::Rect& cached_work_area,
+ gfx::Rect* bounds) const {
+ if (!native_app_window_)
+ return;
+ if (!bounds)
+ return;
+
+ *bounds = cached_bounds;
+ gfx::Rect work_area = native_app_window_->GetWindowWorkArea();
+
+ // Reposition and resize the bounds if the saved_work_area is different from
+ // the current work area and the current work area doesn't completely contain
+ // the bounds.
+ if (!cached_work_area.IsEmpty() &&
+ cached_work_area != work_area &&
+ !work_area.Contains(cached_bounds)) {
+ bounds->set_width(std::min(bounds->width(), work_area.width()));
scheib 2013/06/18 21:52:06 We can not resize to a smaller window than minimum
zhchbin 2013/06/20 06:35:50 Done.
+ bounds->set_height(std::min(bounds->height(), work_area.height()));
+ bounds->set_x(
+ std::max(work_area.x(),
+ std::min(bounds->x(), work_area.right() - bounds->width())));
+ bounds->set_y(
+ std::max(work_area.y(),
+ std::min(bounds->y(), work_area.bottom() - bounds->height())));
+ }
+}
+
+
// static
SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
const std::vector<extensions::DraggableRegion>& regions) {

Powered by Google App Engine
This is Rietveld 408576698