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

Side by Side Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 17564005: Place newly created app windows on screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/extensions/shell_window.h" 5 #include "chrome/browser/ui/extensions/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/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/app_window_contents.h" 10 #include "chrome/browser/extensions/app_window_contents.h"
(...skipping 28 matching lines...) Expand all
39 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
40 #include "content/public/browser/notification_types.h" 40 #include "content/public/browser/notification_types.h"
41 #include "content/public/browser/render_view_host.h" 41 #include "content/public/browser/render_view_host.h"
42 #include "content/public/browser/resource_dispatcher_host.h" 42 #include "content/public/browser/resource_dispatcher_host.h"
43 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
44 #include "content/public/common/media_stream_request.h" 44 #include "content/public/common/media_stream_request.h"
45 #include "extensions/browser/view_type_utils.h" 45 #include "extensions/browser/view_type_utils.h"
46 #include "skia/ext/image_operations.h" 46 #include "skia/ext/image_operations.h"
47 #include "third_party/skia/include/core/SkRegion.h" 47 #include "third_party/skia/include/core/SkRegion.h"
48 #include "ui/gfx/image/image_skia.h" 48 #include "ui/gfx/image/image_skia.h"
49 #include "ui/gfx/screen.h"
49 50
50 #if defined(USE_ASH) 51 #if defined(USE_ASH)
51 #include "ash/launcher/launcher_types.h" 52 #include "ash/launcher/launcher_types.h"
52 #endif 53 #endif
53 54
54 using content::ConsoleMessageLevel; 55 using content::ConsoleMessageLevel;
55 using content::WebContents; 56 using content::WebContents;
56 using extensions::APIPermission; 57 using extensions::APIPermission;
57 using web_modal::WebContentsModalDialogHost; 58 using web_modal::WebContentsModalDialogHost;
58 using web_modal::WebContentsModalDialogManager; 59 using web_modal::WebContentsModalDialogManager;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // the window on the main screen in a platform-defined manner. 154 // the window on the main screen in a platform-defined manner.
154 155
155 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; 156 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
156 if (!params.window_key.empty()) { 157 if (!params.window_key.empty()) {
157 window_key_ = params.window_key; 158 window_key_ = params.window_key;
158 159
159 apps::ShellWindowGeometryCache* cache = 160 apps::ShellWindowGeometryCache* cache =
160 apps::ShellWindowGeometryCache::Get(profile()); 161 apps::ShellWindowGeometryCache::Get(profile());
161 162
162 gfx::Rect cached_bounds; 163 gfx::Rect cached_bounds;
163 if (cache->GetGeometry(extension()->id(), params.window_key, 164 gfx::Rect cached_screen_bounds;
164 &cached_bounds, &cached_state)) { 165 if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds,
166 &cached_screen_bounds, &cached_state)) {
165 bounds = cached_bounds; 167 bounds = cached_bounds;
168 // App window has cached screen bounds, make sure it fits on screen in
169 // case of the screen resolution changed before show on windows platform.
benwells 2013/06/22 00:56:02 nit: in case the screen ... (delete of).
scheib 2013/06/23 04:43:37 Done.
170 if (!cached_screen_bounds.IsEmpty()) {
171 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
172 gfx::Display display = screen->GetDisplayMatching(cached_bounds);
173 gfx::Rect current_screen_bounds = display.work_area();
174 AdjustBoundsToBeVisibleOnScreen(cached_bounds,
175 cached_screen_bounds,
176 current_screen_bounds,
177 params.minimum_size,
178 &bounds);
179 }
166 } 180 }
167 } 181 }
168 182
169 CreateParams new_params = params; 183 CreateParams new_params = params;
170 184
171 gfx::Size& minimum_size = new_params.minimum_size; 185 gfx::Size& minimum_size = new_params.minimum_size;
172 gfx::Size& maximum_size = new_params.maximum_size; 186 gfx::Size& maximum_size = new_params.maximum_size;
173 187
174 // In the case that minimum size > maximum size, we consider the minimum 188 // In the case that minimum size > maximum size, we consider the minimum
175 // size to be more important. 189 // size to be more important.
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 if (window_key_.empty()) 625 if (window_key_.empty())
612 return; 626 return;
613 if (!native_app_window_) 627 if (!native_app_window_)
614 return; 628 return;
615 629
616 apps::ShellWindowGeometryCache* cache = 630 apps::ShellWindowGeometryCache* cache =
617 apps::ShellWindowGeometryCache::Get(profile()); 631 apps::ShellWindowGeometryCache::Get(profile());
618 632
619 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); 633 gfx::Rect bounds = native_app_window_->GetRestoredBounds();
620 bounds.Inset(native_app_window_->GetFrameInsets()); 634 bounds.Inset(native_app_window_->GetFrameInsets());
635 gfx::Rect screen_bounds =
636 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area();
621 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); 637 ui::WindowShowState window_state = native_app_window_->GetRestoredState();
622 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); 638 cache->SaveGeometry(extension()->id(),
639 window_key_,
640 bounds,
641 screen_bounds,
642 window_state);
643 }
644
645 void ShellWindow::AdjustBoundsToBeVisibleOnScreen(
646 const gfx::Rect& cached_bounds,
647 const gfx::Rect& cached_screen_bounds,
648 const gfx::Rect& current_screen_bounds,
649 const gfx::Size& minimum_size,
650 gfx::Rect* bounds) const {
651 if (!bounds)
652 return;
653
654 *bounds = cached_bounds;
655
656 // Reposition and resize the bounds if the cached_screen_bounds is different
657 // from the current screen bounds and the current screen bounds doesn't
658 // completely contain the bounds.
659 if (!cached_screen_bounds.IsEmpty() &&
660 cached_screen_bounds != current_screen_bounds &&
661 !current_screen_bounds.Contains(cached_bounds)) {
662 bounds->set_width(
663 std::max(minimum_size.width(),
664 std::min(bounds->width(), current_screen_bounds.width())));
665 bounds->set_height(
666 std::max(minimum_size.height(),
667 std::min(bounds->height(), current_screen_bounds.height())));
668 bounds->set_x(
669 std::max(current_screen_bounds.x(),
670 std::min(bounds->x(),
671 current_screen_bounds.right() - bounds->width())));
672 bounds->set_y(
673 std::max(current_screen_bounds.y(),
674 std::min(bounds->y(),
675 current_screen_bounds.bottom() - bounds->height())));
676 }
623 } 677 }
624 678
625 // static 679 // static
626 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( 680 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
627 const std::vector<extensions::DraggableRegion>& regions) { 681 const std::vector<extensions::DraggableRegion>& regions) {
628 SkRegion* sk_region = new SkRegion; 682 SkRegion* sk_region = new SkRegion;
629 for (std::vector<extensions::DraggableRegion>::const_iterator iter = 683 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
630 regions.begin(); 684 regions.begin();
631 iter != regions.end(); ++iter) { 685 iter != regions.end(); ++iter) {
632 const extensions::DraggableRegion& region = *iter; 686 const extensions::DraggableRegion& region = *iter;
633 sk_region->op( 687 sk_region->op(
634 region.bounds.x(), 688 region.bounds.x(),
635 region.bounds.y(), 689 region.bounds.y(),
636 region.bounds.right(), 690 region.bounds.right(),
637 region.bounds.bottom(), 691 region.bounds.bottom(),
638 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 692 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
639 } 693 }
640 return sk_region; 694 return sk_region;
641 } 695 }
642 696
643 void ShellWindow::DisableExternalOpenForTesting() { 697 void ShellWindow::DisableExternalOpenForTesting() {
644 disable_external_open_for_testing_ = true; 698 disable_external_open_for_testing_ = true;
645 } 699 }
646 700
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698