OLD | NEW |
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 Loading... |
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 Loading... |
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 #if defined(OS_WIN) |
| 169 // App window has cached screen bounds, make sure it fits on screen in |
| 170 // case of the screen resolution changed before show on windows platform. |
| 171 if (!cached_screen_bounds.IsEmpty()) { |
| 172 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 173 gfx::Display display = screen->GetDisplayMatching(cached_bounds); |
| 174 gfx::Rect current_screen_bounds = display.work_area(); |
| 175 AdjustBoundsToBeVisibleOnScreen(cached_bounds, |
| 176 cached_screen_bounds, |
| 177 current_screen_bounds, |
| 178 params.minimum_size, |
| 179 &bounds); |
| 180 } |
| 181 #endif |
166 } | 182 } |
167 } | 183 } |
168 | 184 |
169 CreateParams new_params = params; | 185 CreateParams new_params = params; |
170 | 186 |
171 gfx::Size& minimum_size = new_params.minimum_size; | 187 gfx::Size& minimum_size = new_params.minimum_size; |
172 gfx::Size& maximum_size = new_params.maximum_size; | 188 gfx::Size& maximum_size = new_params.maximum_size; |
173 | 189 |
174 // In the case that minimum size > maximum size, we consider the minimum | 190 // In the case that minimum size > maximum size, we consider the minimum |
175 // size to be more important. | 191 // size to be more important. |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 if (window_key_.empty()) | 627 if (window_key_.empty()) |
612 return; | 628 return; |
613 if (!native_app_window_) | 629 if (!native_app_window_) |
614 return; | 630 return; |
615 | 631 |
616 apps::ShellWindowGeometryCache* cache = | 632 apps::ShellWindowGeometryCache* cache = |
617 apps::ShellWindowGeometryCache::Get(profile()); | 633 apps::ShellWindowGeometryCache::Get(profile()); |
618 | 634 |
619 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 635 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
620 bounds.Inset(native_app_window_->GetFrameInsets()); | 636 bounds.Inset(native_app_window_->GetFrameInsets()); |
| 637 gfx::Rect screen_bounds = |
| 638 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); |
621 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 639 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
622 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); | 640 cache->SaveGeometry(extension()->id(), |
| 641 window_key_, |
| 642 bounds, |
| 643 screen_bounds, |
| 644 window_state); |
| 645 } |
| 646 |
| 647 void ShellWindow::AdjustBoundsToBeVisibleOnScreen( |
| 648 const gfx::Rect& cached_bounds, |
| 649 const gfx::Rect& cached_screen_bounds, |
| 650 const gfx::Rect& current_screen_bounds, |
| 651 const gfx::Size& minimum_size, |
| 652 gfx::Rect* bounds) const { |
| 653 if (!bounds) |
| 654 return; |
| 655 |
| 656 *bounds = cached_bounds; |
| 657 |
| 658 // Reposition and resize the bounds if the cached_screen_bounds is different |
| 659 // from the current screen bounds and the current screen bounds doesn't |
| 660 // completely contain the bounds. |
| 661 if (!cached_screen_bounds.IsEmpty() && |
| 662 cached_screen_bounds != current_screen_bounds && |
| 663 !current_screen_bounds.Contains(cached_bounds)) { |
| 664 bounds->set_width( |
| 665 std::max(minimum_size.width(), |
| 666 std::min(bounds->width(), current_screen_bounds.width()))); |
| 667 bounds->set_height( |
| 668 std::max(minimum_size.height(), |
| 669 std::min(bounds->height(), current_screen_bounds.height()))); |
| 670 bounds->set_x( |
| 671 std::max(current_screen_bounds.x(), |
| 672 std::min(bounds->x(), |
| 673 current_screen_bounds.right() - bounds->width()))); |
| 674 bounds->set_y( |
| 675 std::max(current_screen_bounds.y(), |
| 676 std::min(bounds->y(), |
| 677 current_screen_bounds.bottom() - bounds->height()))); |
| 678 } |
623 } | 679 } |
624 | 680 |
625 // static | 681 // static |
626 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( | 682 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( |
627 const std::vector<extensions::DraggableRegion>& regions) { | 683 const std::vector<extensions::DraggableRegion>& regions) { |
628 SkRegion* sk_region = new SkRegion; | 684 SkRegion* sk_region = new SkRegion; |
629 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | 685 for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
630 regions.begin(); | 686 regions.begin(); |
631 iter != regions.end(); ++iter) { | 687 iter != regions.end(); ++iter) { |
632 const extensions::DraggableRegion& region = *iter; | 688 const extensions::DraggableRegion& region = *iter; |
633 sk_region->op( | 689 sk_region->op( |
634 region.bounds.x(), | 690 region.bounds.x(), |
635 region.bounds.y(), | 691 region.bounds.y(), |
636 region.bounds.right(), | 692 region.bounds.right(), |
637 region.bounds.bottom(), | 693 region.bounds.bottom(), |
638 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 694 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
639 } | 695 } |
640 return sk_region; | 696 return sk_region; |
641 } | 697 } |
642 | 698 |
643 void ShellWindow::DisableExternalOpenForTesting() { | 699 void ShellWindow::DisableExternalOpenForTesting() { |
644 disable_external_open_for_testing_ = true; | 700 disable_external_open_for_testing_ = true; |
645 } | 701 } |
646 | 702 |
OLD | NEW |