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

Side by Side Diff: apps/app_window.cc

Issue 186343002: Create windows for new app window bounds API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 6 years, 9 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
« no previous file with comments | « apps/app_window.h ('k') | apps/size_constraints.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "apps/app_window.h" 5 #include "apps/app_window.h"
6 6
7 #include <algorithm>
8
7 #include "apps/app_window_geometry_cache.h" 9 #include "apps/app_window_geometry_cache.h"
8 #include "apps/app_window_registry.h" 10 #include "apps/app_window_registry.h"
9 #include "apps/apps_client.h" 11 #include "apps/apps_client.h"
10 #include "apps/size_constraints.h" 12 #include "apps/size_constraints.h"
11 #include "apps/ui/native_app_window.h" 13 #include "apps/ui/native_app_window.h"
12 #include "base/command_line.h" 14 #include "base/command_line.h"
13 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 SetConstraintProperty("minWidth", min_size.width(), bounds_properties.get()); 90 SetConstraintProperty("minWidth", min_size.width(), bounds_properties.get());
89 SetConstraintProperty( 91 SetConstraintProperty(
90 "minHeight", min_size.height(), bounds_properties.get()); 92 "minHeight", min_size.height(), bounds_properties.get());
91 SetConstraintProperty("maxWidth", max_size.width(), bounds_properties.get()); 93 SetConstraintProperty("maxWidth", max_size.width(), bounds_properties.get());
92 SetConstraintProperty( 94 SetConstraintProperty(
93 "maxHeight", max_size.height(), bounds_properties.get()); 95 "maxHeight", max_size.height(), bounds_properties.get());
94 96
95 window_properties->Set(bounds_name, bounds_properties.release()); 97 window_properties->Set(bounds_name, bounds_properties.release());
96 } 98 }
97 99
100 // Combines the constraints of the content and window, and returns constraints
101 // for the window.
102 gfx::Size GetCombinedWindowConstraints(const gfx::Size& window_constraints,
103 const gfx::Size& content_constraints,
104 const gfx::Insets& frame_insets) {
105 gfx::Size combined_constraints(window_constraints);
106 if (content_constraints.width() > 0) {
107 combined_constraints.set_width(
108 content_constraints.width() + frame_insets.width());
109 }
110 if (content_constraints.height() > 0) {
111 combined_constraints.set_height(
112 content_constraints.height() + frame_insets.height());
113 }
114 return combined_constraints;
115 }
116
117 // Combines the constraints of the content and window, and returns constraints
118 // for the content.
119 gfx::Size GetCombinedContentConstraints(const gfx::Size& window_constraints,
120 const gfx::Size& content_constraints,
121 const gfx::Insets& frame_insets) {
122 gfx::Size combined_constraints(content_constraints);
123 if (window_constraints.width() > 0) {
124 combined_constraints.set_width(
125 std::max(0, window_constraints.width() - frame_insets.width()));
126 }
127 if (window_constraints.height() > 0) {
128 combined_constraints.set_height(
129 std::max(0, window_constraints.height() - frame_insets.height()));
130 }
131 return combined_constraints;
132 }
133
98 } // namespace 134 } // namespace
99 135
136 // AppWindow::BoundsSpecification
137
138 const int AppWindow::BoundsSpecification::kUnspecifiedPosition = INT_MIN;
139
140 AppWindow::BoundsSpecification::BoundsSpecification()
141 : bounds(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0) {}
142
143 AppWindow::BoundsSpecification::~BoundsSpecification() {}
144
145 void AppWindow::BoundsSpecification::ResetBounds() {
146 bounds.SetRect(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0);
147 }
148
149 // AppWindow::CreateParams
150
100 AppWindow::CreateParams::CreateParams() 151 AppWindow::CreateParams::CreateParams()
101 : window_type(AppWindow::WINDOW_TYPE_DEFAULT), 152 : window_type(AppWindow::WINDOW_TYPE_DEFAULT),
102 frame(AppWindow::FRAME_CHROME), 153 frame(AppWindow::FRAME_CHROME),
103 has_frame_color(false), 154 has_frame_color(false),
104 transparent_background(false), 155 transparent_background(false),
105 bounds(INT_MIN, INT_MIN, 0, 0),
106 creator_process_id(0), 156 creator_process_id(0),
107 state(ui::SHOW_STATE_DEFAULT), 157 state(ui::SHOW_STATE_DEFAULT),
108 hidden(false), 158 hidden(false),
109 resizable(true), 159 resizable(true),
110 focused(true), 160 focused(true),
111 always_on_top(false) {} 161 always_on_top(false) {}
112 162
113 AppWindow::CreateParams::~CreateParams() {} 163 AppWindow::CreateParams::~CreateParams() {}
114 164
165 gfx::Rect AppWindow::CreateParams::GetInitialWindowBounds(
166 const gfx::Insets& frame_insets) const {
167 // Combine into a single window bounds.
168 gfx::Rect combined_bounds(window_spec.bounds);
169 if (content_spec.bounds.x() != BoundsSpecification::kUnspecifiedPosition)
170 combined_bounds.set_x(content_spec.bounds.x() - frame_insets.left());
171 if (content_spec.bounds.y() != BoundsSpecification::kUnspecifiedPosition)
172 combined_bounds.set_y(content_spec.bounds.y() - frame_insets.top());
173 if (content_spec.bounds.width() > 0) {
174 combined_bounds.set_width(
175 content_spec.bounds.width() + frame_insets.width());
176 }
177 if (content_spec.bounds.height() > 0) {
178 combined_bounds.set_height(
179 content_spec.bounds.height() + frame_insets.height());
180 }
181
182 // Constrain the bounds.
183 SizeConstraints constraints(
184 GetCombinedWindowConstraints(
185 window_spec.minimum_size, content_spec.minimum_size, frame_insets),
186 GetCombinedWindowConstraints(
187 window_spec.maximum_size, content_spec.maximum_size, frame_insets));
188 combined_bounds.set_size(constraints.ClampSize(combined_bounds.size()));
189
190 return combined_bounds;
191 }
192
193 gfx::Size AppWindow::CreateParams::GetContentMinimumSize(
194 const gfx::Insets& frame_insets) const {
195 return GetCombinedContentConstraints(window_spec.minimum_size,
196 content_spec.minimum_size,
197 frame_insets);
198 }
199
200 gfx::Size AppWindow::CreateParams::GetContentMaximumSize(
201 const gfx::Insets& frame_insets) const {
202 return GetCombinedContentConstraints(window_spec.maximum_size,
203 content_spec.maximum_size,
204 frame_insets);
205 }
206
207 gfx::Size AppWindow::CreateParams::GetWindowMinimumSize(
208 const gfx::Insets& frame_insets) const {
209 return GetCombinedWindowConstraints(window_spec.minimum_size,
210 content_spec.minimum_size,
211 frame_insets);
212 }
213
214 gfx::Size AppWindow::CreateParams::GetWindowMaximumSize(
215 const gfx::Insets& frame_insets) const {
216 return GetCombinedWindowConstraints(window_spec.maximum_size,
217 content_spec.maximum_size,
218 frame_insets);
219 }
220
221 // AppWindow::Delegate
222
115 AppWindow::Delegate::~Delegate() {} 223 AppWindow::Delegate::~Delegate() {}
116 224
225 // AppWindow
226
117 AppWindow::AppWindow(BrowserContext* context, 227 AppWindow::AppWindow(BrowserContext* context,
118 Delegate* delegate, 228 Delegate* delegate,
119 const extensions::Extension* extension) 229 const extensions::Extension* extension)
120 : browser_context_(context), 230 : browser_context_(context),
121 extension_(extension), 231 extension_(extension),
122 extension_id_(extension->id()), 232 extension_id_(extension->id()),
123 window_type_(WINDOW_TYPE_DEFAULT), 233 window_type_(WINDOW_TYPE_DEFAULT),
124 delegate_(delegate), 234 delegate_(delegate),
125 image_loader_ptr_factory_(this), 235 image_loader_ptr_factory_(this),
126 fullscreen_types_(FULLSCREEN_TYPE_NONE), 236 fullscreen_types_(FULLSCREEN_TYPE_NONE),
(...skipping 20 matching lines...) Expand all
147 delegate_->InitWebContents(web_contents); 257 delegate_->InitWebContents(web_contents);
148 WebContentsModalDialogManager::CreateForWebContents(web_contents); 258 WebContentsModalDialogManager::CreateForWebContents(web_contents);
149 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents); 259 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents);
150 260
151 web_contents->SetDelegate(this); 261 web_contents->SetDelegate(this);
152 WebContentsModalDialogManager::FromWebContents(web_contents) 262 WebContentsModalDialogManager::FromWebContents(web_contents)
153 ->SetDelegate(this); 263 ->SetDelegate(this);
154 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_WINDOW); 264 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_WINDOW);
155 265
156 // Initialize the window 266 // Initialize the window
157 CreateParams new_params = LoadDefaultsAndConstrain(params); 267 CreateParams new_params = LoadDefaults(params);
158 window_type_ = new_params.window_type; 268 window_type_ = new_params.window_type;
159 window_key_ = new_params.window_key; 269 window_key_ = new_params.window_key;
160 270
161 // Windows cannot be always-on-top in fullscreen mode for security reasons. 271 // Windows cannot be always-on-top in fullscreen mode for security reasons.
162 cached_always_on_top_ = new_params.always_on_top; 272 cached_always_on_top_ = new_params.always_on_top;
163 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) 273 if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
164 new_params.always_on_top = false; 274 new_params.always_on_top = false;
165 275
166 native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params)); 276 native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params));
167 277
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 client->GetOriginalContext(browser_context_))); 311 client->GetOriginalContext(browser_context_)));
202 312
203 app_window_contents_->LoadContents(new_params.creator_process_id); 313 app_window_contents_->LoadContents(new_params.creator_process_id);
204 314
205 if (CommandLine::ForCurrentProcess()->HasSwitch( 315 if (CommandLine::ForCurrentProcess()->HasSwitch(
206 switches::kEnableAppsShowOnFirstPaint)) { 316 switches::kEnableAppsShowOnFirstPaint)) {
207 // We want to show the window only when the content has been painted. For 317 // We want to show the window only when the content has been painted. For
208 // that to happen, we need to define a size for the content, otherwise the 318 // that to happen, we need to define a size for the content, otherwise the
209 // layout will happen in a 0x0 area. 319 // layout will happen in a 0x0 area.
210 // Note: WebContents::GetView() is guaranteed to be non-null. 320 // Note: WebContents::GetView() is guaranteed to be non-null.
211 web_contents->GetView()->SizeContents(new_params.bounds.size()); 321 gfx::Insets frame_insets = native_app_window_->GetFrameInsets();
322 gfx::Rect initial_bounds = new_params.GetInitialWindowBounds(frame_insets);
323 initial_bounds.Inset(frame_insets);
324 web_contents->GetView()->SizeContents(initial_bounds.size());
212 } 325 }
213 326
214 // Prevent the browser process from shutting down while this window is open. 327 // Prevent the browser process from shutting down while this window is open.
215 AppsClient::Get()->IncrementKeepAliveCount(); 328 AppsClient::Get()->IncrementKeepAliveCount();
216 329
217 UpdateExtensionAppIcon(); 330 UpdateExtensionAppIcon();
218 331
219 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); 332 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this);
220 } 333 }
221 334
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 #endif 625 #endif
513 fullscreen_types_ |= FULLSCREEN_TYPE_OS; 626 fullscreen_types_ |= FULLSCREEN_TYPE_OS;
514 SetNativeWindowFullscreen(); 627 SetNativeWindowFullscreen();
515 } 628 }
516 629
517 void AppWindow::ForcedFullscreen() { 630 void AppWindow::ForcedFullscreen() {
518 fullscreen_types_ |= FULLSCREEN_TYPE_FORCED; 631 fullscreen_types_ |= FULLSCREEN_TYPE_FORCED;
519 SetNativeWindowFullscreen(); 632 SetNativeWindowFullscreen();
520 } 633 }
521 634
522 void AppWindow::SetMinimumSize(const gfx::Size& min_size) { 635 void AppWindow::SetContentMinimumSize(const gfx::Size& min_size) {
523 native_app_window_->SetMinimumSize(min_size); 636 native_app_window_->SetContentMinimumSize(min_size);
524 OnSizeConstraintsChanged(); 637 OnSizeConstraintsChanged();
525 } 638 }
526 639
527 void AppWindow::SetMaximumSize(const gfx::Size& max_size) { 640 void AppWindow::SetContentMaximumSize(const gfx::Size& max_size) {
528 native_app_window_->SetMaximumSize(max_size); 641 native_app_window_->SetContentMaximumSize(max_size);
529 OnSizeConstraintsChanged(); 642 OnSizeConstraintsChanged();
530 } 643 }
531 644
532 void AppWindow::Show(ShowType show_type) { 645 void AppWindow::Show(ShowType show_type) {
533 if (CommandLine::ForCurrentProcess()->HasSwitch( 646 if (CommandLine::ForCurrentProcess()->HasSwitch(
534 switches::kEnableAppsShowOnFirstPaint)) { 647 switches::kEnableAppsShowOnFirstPaint)) {
535 show_on_first_paint_ = true; 648 show_on_first_paint_ = true;
536 649
537 if (!first_paint_complete_) { 650 if (!first_paint_complete_) {
538 delayed_show_type_ = show_type; 651 delayed_show_type_ = show_type;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 694
582 properties->SetBoolean("fullscreen", 695 properties->SetBoolean("fullscreen",
583 native_app_window_->IsFullscreenOrPending()); 696 native_app_window_->IsFullscreenOrPending());
584 properties->SetBoolean("minimized", native_app_window_->IsMinimized()); 697 properties->SetBoolean("minimized", native_app_window_->IsMinimized());
585 properties->SetBoolean("maximized", native_app_window_->IsMaximized()); 698 properties->SetBoolean("maximized", native_app_window_->IsMaximized());
586 properties->SetBoolean("alwaysOnTop", IsAlwaysOnTop()); 699 properties->SetBoolean("alwaysOnTop", IsAlwaysOnTop());
587 properties->SetBoolean("hasFrameColor", native_app_window_->HasFrameColor()); 700 properties->SetBoolean("hasFrameColor", native_app_window_->HasFrameColor());
588 properties->SetInteger("frameColor", native_app_window_->FrameColor()); 701 properties->SetInteger("frameColor", native_app_window_->FrameColor());
589 702
590 gfx::Rect content_bounds = GetClientBounds(); 703 gfx::Rect content_bounds = GetClientBounds();
704 gfx::Size content_min_size = native_app_window_->GetContentMinimumSize();
705 gfx::Size content_max_size = native_app_window_->GetContentMaximumSize();
591 SetBoundsProperties(content_bounds, 706 SetBoundsProperties(content_bounds,
592 native_app_window_->GetMinimumSize(), 707 content_min_size,
593 native_app_window_->GetMaximumSize(), 708 content_max_size,
594 "innerBounds", 709 "innerBounds",
595 properties); 710 properties);
596 711
597 // TODO(tmdiep): Frame constraints will be implemented in a future patch. 712 gfx::Insets frame_insets = native_app_window_->GetFrameInsets();
598 gfx::Rect frame_bounds = native_app_window_->GetBounds(); 713 gfx::Rect frame_bounds = native_app_window_->GetBounds();
714 gfx::Size frame_min_size =
715 SizeConstraints::AddFrameToConstraints(content_min_size, frame_insets);
716 gfx::Size frame_max_size =
717 SizeConstraints::AddFrameToConstraints(content_max_size, frame_insets);
599 SetBoundsProperties(frame_bounds, 718 SetBoundsProperties(frame_bounds,
600 gfx::Size(), 719 frame_min_size,
601 gfx::Size(), 720 frame_max_size,
602 "outerBounds", 721 "outerBounds",
603 properties); 722 properties);
604 } 723 }
605 724
606 //------------------------------------------------------------------------------ 725 //------------------------------------------------------------------------------
607 // Private methods 726 // Private methods
608 727
609 void AppWindow::UpdateBadgeIcon(const gfx::Image& image) { 728 void AppWindow::UpdateBadgeIcon(const gfx::Image& image) {
610 badge_icon_ = image; 729 badge_icon_ = image;
611 native_app_window_->UpdateBadgeIcon(); 730 native_app_window_->UpdateBadgeIcon();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 delegate_->PreferredIconSize(), 775 delegate_->PreferredIconSize(),
657 extensions::IconsInfo::GetDefaultAppIcon(), 776 extensions::IconsInfo::GetDefaultAppIcon(),
658 this)); 777 this));
659 778
660 // Triggers actual image loading with 1x resources. The 2x resource will 779 // Triggers actual image loading with 1x resources. The 2x resource will
661 // be handled by IconImage class when requested. 780 // be handled by IconImage class when requested.
662 app_icon_image_->image_skia().GetRepresentation(1.0f); 781 app_icon_image_->image_skia().GetRepresentation(1.0f);
663 } 782 }
664 783
665 void AppWindow::OnSizeConstraintsChanged() { 784 void AppWindow::OnSizeConstraintsChanged() {
666 SizeConstraints size_constraints(native_app_window_->GetMinimumSize(), 785 SizeConstraints size_constraints(native_app_window_->GetContentMinimumSize(),
667 native_app_window_->GetMaximumSize()); 786 native_app_window_->GetContentMaximumSize());
668 gfx::Rect bounds = GetClientBounds(); 787 gfx::Rect bounds = GetClientBounds();
669 gfx::Size constrained_size = size_constraints.ClampSize(bounds.size()); 788 gfx::Size constrained_size = size_constraints.ClampSize(bounds.size());
670 if (bounds.size() != constrained_size) { 789 if (bounds.size() != constrained_size) {
671 bounds.set_size(constrained_size); 790 bounds.set_size(constrained_size);
791 bounds.Inset(-native_app_window_->GetFrameInsets());
672 native_app_window_->SetBounds(bounds); 792 native_app_window_->SetBounds(bounds);
673 } 793 }
674 OnNativeWindowChanged(); 794 OnNativeWindowChanged();
675 } 795 }
676 796
677 void AppWindow::SetNativeWindowFullscreen() { 797 void AppWindow::SetNativeWindowFullscreen() {
678 native_app_window_->SetFullscreen(fullscreen_types_); 798 native_app_window_->SetFullscreen(fullscreen_types_);
679 799
680 if (cached_always_on_top_) 800 if (cached_always_on_top_)
681 UpdateNativeAlwaysOnTop(); 801 UpdateNativeAlwaysOnTop();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 void AppWindow::SaveWindowPosition() { 965 void AppWindow::SaveWindowPosition() {
846 if (window_key_.empty()) 966 if (window_key_.empty())
847 return; 967 return;
848 if (!native_app_window_) 968 if (!native_app_window_)
849 return; 969 return;
850 970
851 AppWindowGeometryCache* cache = 971 AppWindowGeometryCache* cache =
852 AppWindowGeometryCache::Get(browser_context()); 972 AppWindowGeometryCache::Get(browser_context());
853 973
854 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); 974 gfx::Rect bounds = native_app_window_->GetRestoredBounds();
855 bounds.Inset(native_app_window_->GetFrameInsets());
856 gfx::Rect screen_bounds = 975 gfx::Rect screen_bounds =
857 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); 976 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area();
858 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); 977 ui::WindowShowState window_state = native_app_window_->GetRestoredState();
859 cache->SaveGeometry( 978 cache->SaveGeometry(
860 extension()->id(), window_key_, bounds, screen_bounds, window_state); 979 extension()->id(), window_key_, bounds, screen_bounds, window_state);
861 } 980 }
862 981
863 void AppWindow::AdjustBoundsToBeVisibleOnScreen( 982 void AppWindow::AdjustBoundsToBeVisibleOnScreen(
864 const gfx::Rect& cached_bounds, 983 const gfx::Rect& cached_bounds,
865 const gfx::Rect& cached_screen_bounds, 984 const gfx::Rect& cached_screen_bounds,
(...skipping 17 matching lines...) Expand all
883 std::max(current_screen_bounds.x(), 1002 std::max(current_screen_bounds.x(),
884 std::min(bounds->x(), 1003 std::min(bounds->x(),
885 current_screen_bounds.right() - bounds->width()))); 1004 current_screen_bounds.right() - bounds->width())));
886 bounds->set_y( 1005 bounds->set_y(
887 std::max(current_screen_bounds.y(), 1006 std::max(current_screen_bounds.y(),
888 std::min(bounds->y(), 1007 std::min(bounds->y(),
889 current_screen_bounds.bottom() - bounds->height()))); 1008 current_screen_bounds.bottom() - bounds->height())));
890 } 1009 }
891 } 1010 }
892 1011
893 AppWindow::CreateParams AppWindow::LoadDefaultsAndConstrain(CreateParams params) 1012 AppWindow::CreateParams AppWindow::LoadDefaults(CreateParams params)
894 const { 1013 const {
895 if (params.bounds.width() == 0) 1014 // Ensure width and height are specified.
896 params.bounds.set_width(kDefaultWidth); 1015 if (params.content_spec.bounds.width() == 0 &&
897 if (params.bounds.height() == 0) 1016 params.window_spec.bounds.width() == 0) {
898 params.bounds.set_height(kDefaultHeight); 1017 params.content_spec.bounds.set_width(kDefaultWidth);
1018 }
1019 if (params.content_spec.bounds.height() == 0 &&
1020 params.window_spec.bounds.height() == 0) {
1021 params.content_spec.bounds.set_height(kDefaultHeight);
1022 }
899 1023
900 // If left and top are left undefined, the native app window will center 1024 // If left and top are left undefined, the native app window will center
901 // the window on the main screen in a platform-defined manner. 1025 // the window on the main screen in a platform-defined manner.
902 1026
903 // Load cached state if it exists. 1027 // Load cached state if it exists.
904 if (!params.window_key.empty()) { 1028 if (!params.window_key.empty()) {
905 AppWindowGeometryCache* cache = 1029 AppWindowGeometryCache* cache =
906 AppWindowGeometryCache::Get(browser_context()); 1030 AppWindowGeometryCache::Get(browser_context());
907 1031
908 gfx::Rect cached_bounds; 1032 gfx::Rect cached_bounds;
909 gfx::Rect cached_screen_bounds; 1033 gfx::Rect cached_screen_bounds;
910 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; 1034 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
911 if (cache->GetGeometry(extension()->id(), 1035 if (cache->GetGeometry(extension()->id(),
912 params.window_key, 1036 params.window_key,
913 &cached_bounds, 1037 &cached_bounds,
914 &cached_screen_bounds, 1038 &cached_screen_bounds,
915 &cached_state)) { 1039 &cached_state)) {
1040
916 // App window has cached screen bounds, make sure it fits on screen in 1041 // App window has cached screen bounds, make sure it fits on screen in
917 // case the screen resolution changed. 1042 // case the screen resolution changed.
918 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 1043 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
919 gfx::Display display = screen->GetDisplayMatching(cached_bounds); 1044 gfx::Display display = screen->GetDisplayMatching(cached_bounds);
920 gfx::Rect current_screen_bounds = display.work_area(); 1045 gfx::Rect current_screen_bounds = display.work_area();
1046 SizeConstraints constraints(params.GetWindowMinimumSize(gfx::Insets()),
1047 params.GetWindowMaximumSize(gfx::Insets()));
921 AdjustBoundsToBeVisibleOnScreen(cached_bounds, 1048 AdjustBoundsToBeVisibleOnScreen(cached_bounds,
922 cached_screen_bounds, 1049 cached_screen_bounds,
923 current_screen_bounds, 1050 current_screen_bounds,
924 params.minimum_size, 1051 constraints.GetMinimumSize(),
925 &params.bounds); 1052 &params.window_spec.bounds);
926 params.state = cached_state; 1053 params.state = cached_state;
1054
1055 // Since we are restoring a cached state, reset the content bounds spec to
1056 // ensure it is not used.
1057 params.content_spec.ResetBounds();
927 } 1058 }
928 } 1059 }
929 1060
930 SizeConstraints size_constraints(params.minimum_size, params.maximum_size);
931 params.bounds.set_size(size_constraints.ClampSize(params.bounds.size()));
932 params.minimum_size = size_constraints.GetMinimumSize();
933 params.maximum_size = size_constraints.GetMaximumSize();
934
935 return params; 1061 return params;
936 } 1062 }
937 1063
938 // static 1064 // static
939 SkRegion* AppWindow::RawDraggableRegionsToSkRegion( 1065 SkRegion* AppWindow::RawDraggableRegionsToSkRegion(
940 const std::vector<extensions::DraggableRegion>& regions) { 1066 const std::vector<extensions::DraggableRegion>& regions) {
941 SkRegion* sk_region = new SkRegion; 1067 SkRegion* sk_region = new SkRegion;
942 for (std::vector<extensions::DraggableRegion>::const_iterator iter = 1068 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
943 regions.begin(); 1069 regions.begin();
944 iter != regions.end(); 1070 iter != regions.end();
945 ++iter) { 1071 ++iter) {
946 const extensions::DraggableRegion& region = *iter; 1072 const extensions::DraggableRegion& region = *iter;
947 sk_region->op( 1073 sk_region->op(
948 region.bounds.x(), 1074 region.bounds.x(),
949 region.bounds.y(), 1075 region.bounds.y(),
950 region.bounds.right(), 1076 region.bounds.right(),
951 region.bounds.bottom(), 1077 region.bounds.bottom(),
952 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 1078 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
953 } 1079 }
954 return sk_region; 1080 return sk_region;
955 } 1081 }
956 1082
957 } // namespace apps 1083 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_window.h ('k') | apps/size_constraints.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698