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

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: Update to windows only. 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
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5d3f4af6c8a6a10ccbecf89a2503c6dbb22bd386..f6b62d882255f6fe7571ad2fd03b98308b871a47 100644
--- a/chrome/browser/ui/extensions/shell_window.cc
+++ b/chrome/browser/ui/extensions/shell_window.cc
@@ -46,6 +46,7 @@
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/screen.h"
#if defined(USE_ASH)
#include "ash/launcher/launcher_types.h"
@@ -160,9 +161,24 @@ void ShellWindow::Init(const GURL& url,
apps::ShellWindowGeometryCache::Get(profile());
gfx::Rect cached_bounds;
- if (cache->GetGeometry(extension()->id(), params.window_key,
- &cached_bounds, &cached_state)) {
+ gfx::Rect cached_screen_bounds;
+ if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds,
+ &cached_screen_bounds, &cached_state)) {
bounds = cached_bounds;
+#if defined(OS_WIN)
+ // App window has cached screen bounds, make sure it fits on screen in
+ // case of the screen resolution changed before show on windows platform.
+ if (!cached_screen_bounds.IsEmpty()) {
+ gfx::Screen* screen = gfx::Screen::GetNativeScreen();
+ gfx::Display display = screen->GetDisplayMatching(cached_bounds);
+ gfx::Rect current_screen_bounds = display.work_area();
+ AdjustBoundsToBeVisibleOnScreen(cached_bounds,
+ cached_screen_bounds,
+ current_screen_bounds,
+ params.minimum_size,
+ &bounds);
+ }
+#endif
}
}
@@ -618,8 +634,48 @@ void ShellWindow::SaveWindowPosition() {
gfx::Rect bounds = native_app_window_->GetRestoredBounds();
bounds.Inset(native_app_window_->GetFrameInsets());
+ gfx::Rect screen_bounds =
+ gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area();
ui::WindowShowState window_state = native_app_window_->GetRestoredState();
- cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state);
+ cache->SaveGeometry(extension()->id(),
+ window_key_,
+ bounds,
+ screen_bounds,
+ window_state);
+}
+
+void ShellWindow::AdjustBoundsToBeVisibleOnScreen(
+ const gfx::Rect& cached_bounds,
+ const gfx::Rect& cached_screen_bounds,
+ const gfx::Rect& current_screen_bounds,
+ const gfx::Size& minimum_size,
+ gfx::Rect* bounds) const {
+ if (!bounds)
+ return;
+
+ *bounds = cached_bounds;
+
+ // Reposition and resize the bounds if the cached_screen_bounds is different
+ // from the current screen bounds and the current screen bounds doesn't
+ // completely contain the bounds.
+ if (!cached_screen_bounds.IsEmpty() &&
+ cached_screen_bounds != current_screen_bounds &&
+ !current_screen_bounds.Contains(cached_bounds)) {
+ bounds->set_width(
+ std::max(minimum_size.width(),
+ std::min(bounds->width(), current_screen_bounds.width())));
+ bounds->set_height(
+ std::max(minimum_size.height(),
+ std::min(bounds->height(), current_screen_bounds.height())));
+ bounds->set_x(
+ std::max(current_screen_bounds.x(),
+ std::min(bounds->x(),
+ current_screen_bounds.right() - bounds->width())));
+ bounds->set_y(
+ std::max(current_screen_bounds.y(),
+ std::min(bounds->y(),
+ current_screen_bounds.bottom() - bounds->height())));
+ }
}
// static
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698