OLD | NEW |
---|---|
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> | |
benwells
2014/03/05 02:33:30
Is this needed?
tmdiep
2014/03/05 03:06:47
Apparently it is if you use std::min/max on VS2013
| |
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 Loading... | |
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_size, | |
benwells
2014/03/05 02:33:30
Nit: I think window_size and content_size should b
| |
103 const gfx::Size& content_size, | |
104 const gfx::Insets& frame_insets) { | |
105 gfx::Size combined_size(window_size); | |
106 if (content_size.width() > 0) | |
107 combined_size.set_width(content_size.width() + frame_insets.width()); | |
108 if (content_size.height() > 0) | |
109 combined_size.set_height(content_size.height() + frame_insets.height()); | |
110 return combined_size; | |
111 } | |
112 | |
113 // Combines the constraints of the content and window, and returns constraints | |
114 // for the content. | |
115 gfx::Size GetCombinedContentConstraints(const gfx::Size& window_size, | |
116 const gfx::Size& content_size, | |
benwells
2014/03/05 02:33:30
Same here
| |
117 const gfx::Insets& frame_insets) { | |
118 gfx::Size combined_size(content_size); | |
119 if (window_size.width() > 0) { | |
120 combined_size.set_width( | |
121 std::max(0, window_size.width() - frame_insets.width())); | |
122 } | |
123 if (window_size.height() > 0) { | |
124 combined_size.set_height( | |
125 std::max(0, window_size.height() - frame_insets.height())); | |
126 } | |
127 return combined_size; | |
128 } | |
129 | |
98 } // namespace | 130 } // namespace |
99 | 131 |
132 // AppWindow::BoundsSpecification | |
133 | |
134 // static | |
tapted
2014/03/05 03:14:03
nit: remove - Don't usually see `// static` for da
| |
135 const int AppWindow::BoundsSpecification::kUnspecifiedPosition = INT_MIN; | |
136 | |
137 AppWindow::BoundsSpecification::BoundsSpecification() | |
138 : bounds(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0) {} | |
139 | |
140 void AppWindow::BoundsSpecification::ResetBounds() { | |
141 bounds.set_x(kUnspecifiedPosition); | |
tapted
2014/03/05 03:14:03
nit: bounds.SetRect(kUnspecifiedPosition, kUnspeci
| |
142 bounds.set_y(kUnspecifiedPosition); | |
143 bounds.set_width(0); | |
144 bounds.set_height(0); | |
145 } | |
146 | |
147 AppWindow::BoundsSpecification::~BoundsSpecification() {} | |
tapted
2014/03/05 03:14:03
nit: move up below constructor
| |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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::InsetConstraints(content_min_size, -frame_insets); | |
716 gfx::Size frame_max_size = | |
717 SizeConstraints::InsetConstraints(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 Loading... | |
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()); | |
tmdiep
2014/03/04 03:13:14
Fixed bug - NativeAppWindow::SetBounds() sets fram
tapted
2014/03/05 03:14:03
Will this shift the origin too? (do we want that?)
tmdiep
2014/03/05 04:29:06
The existing code shifts the origin. With this cha
| |
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 void AppWindow::SaveWindowPosition() { | 971 void AppWindow::SaveWindowPosition() { |
852 if (window_key_.empty()) | 972 if (window_key_.empty()) |
853 return; | 973 return; |
854 if (!native_app_window_) | 974 if (!native_app_window_) |
855 return; | 975 return; |
856 | 976 |
857 AppWindowGeometryCache* cache = | 977 AppWindowGeometryCache* cache = |
858 AppWindowGeometryCache::Get(browser_context()); | 978 AppWindowGeometryCache::Get(browser_context()); |
859 | 979 |
860 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 980 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
861 bounds.Inset(native_app_window_->GetFrameInsets()); | |
tmdiep
2014/03/04 03:13:14
If we store the content bounds in the window geome
| |
862 gfx::Rect screen_bounds = | 981 gfx::Rect screen_bounds = |
863 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); | 982 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); |
864 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 983 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
865 cache->SaveGeometry( | 984 cache->SaveGeometry( |
866 extension()->id(), window_key_, bounds, screen_bounds, window_state); | 985 extension()->id(), window_key_, bounds, screen_bounds, window_state); |
867 } | 986 } |
868 | 987 |
869 void AppWindow::AdjustBoundsToBeVisibleOnScreen( | 988 void AppWindow::AdjustBoundsToBeVisibleOnScreen( |
870 const gfx::Rect& cached_bounds, | 989 const gfx::Rect& cached_bounds, |
871 const gfx::Rect& cached_screen_bounds, | 990 const gfx::Rect& cached_screen_bounds, |
(...skipping 17 matching lines...) Expand all Loading... | |
889 std::max(current_screen_bounds.x(), | 1008 std::max(current_screen_bounds.x(), |
890 std::min(bounds->x(), | 1009 std::min(bounds->x(), |
891 current_screen_bounds.right() - bounds->width()))); | 1010 current_screen_bounds.right() - bounds->width()))); |
892 bounds->set_y( | 1011 bounds->set_y( |
893 std::max(current_screen_bounds.y(), | 1012 std::max(current_screen_bounds.y(), |
894 std::min(bounds->y(), | 1013 std::min(bounds->y(), |
895 current_screen_bounds.bottom() - bounds->height()))); | 1014 current_screen_bounds.bottom() - bounds->height()))); |
896 } | 1015 } |
897 } | 1016 } |
898 | 1017 |
899 AppWindow::CreateParams AppWindow::LoadDefaultsAndConstrain(CreateParams params) | 1018 AppWindow::CreateParams AppWindow::LoadDefaults(CreateParams params) |
900 const { | 1019 const { |
901 if (params.bounds.width() == 0) | 1020 // Ensure width and height are specified. |
902 params.bounds.set_width(kDefaultWidth); | 1021 if (params.content_spec.bounds.width() == 0 && |
903 if (params.bounds.height() == 0) | 1022 params.window_spec.bounds.width() == 0) { |
904 params.bounds.set_height(kDefaultHeight); | 1023 params.window_spec.bounds.set_width(kDefaultWidth); |
benwells
2014/03/05 02:33:30
I think we should set the default on the content_s
tapted
2014/03/05 03:14:03
should this be setting the content_spec instead of
| |
1024 } | |
1025 if (params.content_spec.bounds.height() == 0 && | |
1026 params.window_spec.bounds.height() == 0) { | |
1027 params.window_spec.bounds.set_height(kDefaultHeight); | |
1028 } | |
905 | 1029 |
906 // If left and top are left undefined, the native app window will center | 1030 // If left and top are left undefined, the native app window will center |
907 // the window on the main screen in a platform-defined manner. | 1031 // the window on the main screen in a platform-defined manner. |
908 | 1032 |
909 // Load cached state if it exists. | 1033 // Load cached state if it exists. |
910 if (!params.window_key.empty()) { | 1034 if (!params.window_key.empty()) { |
911 AppWindowGeometryCache* cache = | 1035 AppWindowGeometryCache* cache = |
912 AppWindowGeometryCache::Get(browser_context()); | 1036 AppWindowGeometryCache::Get(browser_context()); |
913 | 1037 |
914 gfx::Rect cached_bounds; | 1038 gfx::Rect cached_bounds; |
915 gfx::Rect cached_screen_bounds; | 1039 gfx::Rect cached_screen_bounds; |
916 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; | 1040 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; |
917 if (cache->GetGeometry(extension()->id(), | 1041 if (cache->GetGeometry(extension()->id(), |
918 params.window_key, | 1042 params.window_key, |
919 &cached_bounds, | 1043 &cached_bounds, |
920 &cached_screen_bounds, | 1044 &cached_screen_bounds, |
921 &cached_state)) { | 1045 &cached_state)) { |
1046 | |
922 // App window has cached screen bounds, make sure it fits on screen in | 1047 // App window has cached screen bounds, make sure it fits on screen in |
923 // case the screen resolution changed. | 1048 // case the screen resolution changed. |
924 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 1049 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
925 gfx::Display display = screen->GetDisplayMatching(cached_bounds); | 1050 gfx::Display display = screen->GetDisplayMatching(cached_bounds); |
926 gfx::Rect current_screen_bounds = display.work_area(); | 1051 gfx::Rect current_screen_bounds = display.work_area(); |
1052 SizeConstraints constraints(params.GetWindowMinimumSize(gfx::Insets()), | |
1053 params.GetWindowMaximumSize(gfx::Insets())); | |
927 AdjustBoundsToBeVisibleOnScreen(cached_bounds, | 1054 AdjustBoundsToBeVisibleOnScreen(cached_bounds, |
928 cached_screen_bounds, | 1055 cached_screen_bounds, |
929 current_screen_bounds, | 1056 current_screen_bounds, |
930 params.minimum_size, | 1057 constraints.GetMinimumSize(), |
931 ¶ms.bounds); | 1058 ¶ms.window_spec.bounds); |
932 params.state = cached_state; | 1059 params.state = cached_state; |
1060 | |
1061 // Since we are restoring a cached state, reset the content bounds spec to | |
1062 // ensure it is not used. | |
1063 params.content_spec.ResetBounds(); | |
933 } | 1064 } |
934 } | 1065 } |
935 | 1066 |
936 SizeConstraints size_constraints(params.minimum_size, params.maximum_size); | |
tmdiep
2014/03/04 03:13:14
Because the API lets you specify content or window
| |
937 params.bounds.set_size(size_constraints.ClampSize(params.bounds.size())); | |
938 params.minimum_size = size_constraints.GetMinimumSize(); | |
939 params.maximum_size = size_constraints.GetMaximumSize(); | |
940 | |
941 return params; | 1067 return params; |
942 } | 1068 } |
943 | 1069 |
944 // static | 1070 // static |
945 SkRegion* AppWindow::RawDraggableRegionsToSkRegion( | 1071 SkRegion* AppWindow::RawDraggableRegionsToSkRegion( |
946 const std::vector<extensions::DraggableRegion>& regions) { | 1072 const std::vector<extensions::DraggableRegion>& regions) { |
947 SkRegion* sk_region = new SkRegion; | 1073 SkRegion* sk_region = new SkRegion; |
948 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | 1074 for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
949 regions.begin(); | 1075 regions.begin(); |
950 iter != regions.end(); | 1076 iter != regions.end(); |
951 ++iter) { | 1077 ++iter) { |
952 const extensions::DraggableRegion& region = *iter; | 1078 const extensions::DraggableRegion& region = *iter; |
953 sk_region->op( | 1079 sk_region->op( |
954 region.bounds.x(), | 1080 region.bounds.x(), |
955 region.bounds.y(), | 1081 region.bounds.y(), |
956 region.bounds.right(), | 1082 region.bounds.right(), |
957 region.bounds.bottom(), | 1083 region.bounds.bottom(), |
958 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 1084 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
959 } | 1085 } |
960 return sk_region; | 1086 return sk_region; |
961 } | 1087 } |
962 | 1088 |
963 } // namespace apps | 1089 } // namespace apps |
OLD | NEW |