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 // App window has cached screen bounds, make sure it fits on screen in |
| 169 // case the screen resolution changed. |
| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 if (window_key_.empty()) | 628 if (window_key_.empty()) |
615 return; | 629 return; |
616 if (!native_app_window_) | 630 if (!native_app_window_) |
617 return; | 631 return; |
618 | 632 |
619 apps::ShellWindowGeometryCache* cache = | 633 apps::ShellWindowGeometryCache* cache = |
620 apps::ShellWindowGeometryCache::Get(profile()); | 634 apps::ShellWindowGeometryCache::Get(profile()); |
621 | 635 |
622 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 636 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
623 bounds.Inset(native_app_window_->GetFrameInsets()); | 637 bounds.Inset(native_app_window_->GetFrameInsets()); |
| 638 gfx::Rect screen_bounds = |
| 639 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); |
624 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 640 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
625 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); | 641 cache->SaveGeometry(extension()->id(), |
| 642 window_key_, |
| 643 bounds, |
| 644 screen_bounds, |
| 645 window_state); |
| 646 } |
| 647 |
| 648 void ShellWindow::AdjustBoundsToBeVisibleOnScreen( |
| 649 const gfx::Rect& cached_bounds, |
| 650 const gfx::Rect& cached_screen_bounds, |
| 651 const gfx::Rect& current_screen_bounds, |
| 652 const gfx::Size& minimum_size, |
| 653 gfx::Rect* bounds) const { |
| 654 if (!bounds) |
| 655 return; |
| 656 |
| 657 *bounds = cached_bounds; |
| 658 |
| 659 // Reposition and resize the bounds if the cached_screen_bounds is different |
| 660 // from the current screen bounds and the current screen bounds doesn't |
| 661 // completely contain the bounds. |
| 662 if (!cached_screen_bounds.IsEmpty() && |
| 663 cached_screen_bounds != current_screen_bounds && |
| 664 !current_screen_bounds.Contains(cached_bounds)) { |
| 665 bounds->set_width( |
| 666 std::max(minimum_size.width(), |
| 667 std::min(bounds->width(), current_screen_bounds.width()))); |
| 668 bounds->set_height( |
| 669 std::max(minimum_size.height(), |
| 670 std::min(bounds->height(), current_screen_bounds.height()))); |
| 671 bounds->set_x( |
| 672 std::max(current_screen_bounds.x(), |
| 673 std::min(bounds->x(), |
| 674 current_screen_bounds.right() - bounds->width()))); |
| 675 bounds->set_y( |
| 676 std::max(current_screen_bounds.y(), |
| 677 std::min(bounds->y(), |
| 678 current_screen_bounds.bottom() - bounds->height()))); |
| 679 } |
626 } | 680 } |
627 | 681 |
628 // static | 682 // static |
629 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( | 683 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( |
630 const std::vector<extensions::DraggableRegion>& regions) { | 684 const std::vector<extensions::DraggableRegion>& regions) { |
631 SkRegion* sk_region = new SkRegion; | 685 SkRegion* sk_region = new SkRegion; |
632 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | 686 for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
633 regions.begin(); | 687 regions.begin(); |
634 iter != regions.end(); ++iter) { | 688 iter != regions.end(); ++iter) { |
635 const extensions::DraggableRegion& region = *iter; | 689 const extensions::DraggableRegion& region = *iter; |
636 sk_region->op( | 690 sk_region->op( |
637 region.bounds.x(), | 691 region.bounds.x(), |
638 region.bounds.y(), | 692 region.bounds.y(), |
639 region.bounds.right(), | 693 region.bounds.right(), |
640 region.bounds.bottom(), | 694 region.bounds.bottom(), |
641 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 695 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
642 } | 696 } |
643 return sk_region; | 697 return sk_region; |
644 } | 698 } |
645 | 699 |
646 void ShellWindow::DisableExternalOpenForTesting() { | 700 void ShellWindow::DisableExternalOpenForTesting() { |
647 disable_external_open_for_testing_ = true; | 701 disable_external_open_for_testing_ = true; |
648 } | 702 } |
649 | 703 |
OLD | NEW |