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

Side by Side Diff: apps/app_window.cc

Issue 484613002: Move apps::SizeConstraints to extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: extensions/browser/app_window Created 6 years, 4 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
« no previous file with comments | « no previous file | apps/apps.gypi » ('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> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "apps/app_delegate.h" 11 #include "apps/app_delegate.h"
12 #include "apps/app_web_contents_helper.h" 12 #include "apps/app_web_contents_helper.h"
13 #include "apps/app_window_geometry_cache.h" 13 #include "apps/app_window_geometry_cache.h"
14 #include "apps/app_window_registry.h" 14 #include "apps/app_window_registry.h"
15 #include "apps/size_constraints.h"
16 #include "apps/ui/apps_client.h" 15 #include "apps/ui/apps_client.h"
17 #include "apps/ui/native_app_window.h" 16 #include "apps/ui/native_app_window.h"
18 #include "apps/ui/web_contents_sizer.h" 17 #include "apps/ui/web_contents_sizer.h"
19 #include "base/command_line.h" 18 #include "base/command_line.h"
20 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/values.h" 21 #include "base/values.h"
23 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 23 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
25 #include "chrome/browser/extensions/suggest_permission_util.h" 24 #include "chrome/browser/extensions/suggest_permission_util.h"
26 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
27 #include "components/web_modal/web_contents_modal_dialog_manager.h" 26 #include "components/web_modal/web_contents_modal_dialog_manager.h"
28 #include "content/public/browser/browser_context.h" 27 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/invalidate_type.h" 28 #include "content/public/browser/invalidate_type.h"
30 #include "content/public/browser/navigation_entry.h" 29 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_source.h" 32 #include "content/public/browser/notification_source.h"
34 #include "content/public/browser/notification_types.h" 33 #include "content/public/browser/notification_types.h"
35 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
36 #include "content/public/browser/resource_dispatcher_host.h" 35 #include "content/public/browser/resource_dispatcher_host.h"
37 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
38 #include "content/public/common/content_switches.h" 37 #include "content/public/common/content_switches.h"
39 #include "content/public/common/media_stream_request.h" 38 #include "content/public/common/media_stream_request.h"
39 #include "extensions/browser/app_window/size_constraints.h"
40 #include "extensions/browser/extension_registry.h" 40 #include "extensions/browser/extension_registry.h"
41 #include "extensions/browser/extension_system.h" 41 #include "extensions/browser/extension_system.h"
42 #include "extensions/browser/extensions_browser_client.h" 42 #include "extensions/browser/extensions_browser_client.h"
43 #include "extensions/browser/notification_types.h" 43 #include "extensions/browser/notification_types.h"
44 #include "extensions/browser/process_manager.h" 44 #include "extensions/browser/process_manager.h"
45 #include "extensions/browser/view_type_utils.h" 45 #include "extensions/browser/view_type_utils.h"
46 #include "extensions/common/draggable_region.h" 46 #include "extensions/common/draggable_region.h"
47 #include "extensions/common/extension.h" 47 #include "extensions/common/extension.h"
48 #include "extensions/common/manifest_handlers/icons_handler.h" 48 #include "extensions/common/manifest_handlers/icons_handler.h"
49 #include "extensions/common/permissions/permissions_data.h" 49 #include "extensions/common/permissions/permissions_data.h"
(...skipping 17 matching lines...) Expand all
67 namespace apps { 67 namespace apps {
68 68
69 namespace { 69 namespace {
70 70
71 const int kDefaultWidth = 512; 71 const int kDefaultWidth = 512;
72 const int kDefaultHeight = 384; 72 const int kDefaultHeight = 384;
73 73
74 void SetConstraintProperty(const std::string& name, 74 void SetConstraintProperty(const std::string& name,
75 int value, 75 int value,
76 base::DictionaryValue* bounds_properties) { 76 base::DictionaryValue* bounds_properties) {
77 if (value != SizeConstraints::kUnboundedSize) 77 if (value != extensions::SizeConstraints::kUnboundedSize)
78 bounds_properties->SetInteger(name, value); 78 bounds_properties->SetInteger(name, value);
79 else 79 else
80 bounds_properties->Set(name, base::Value::CreateNullValue()); 80 bounds_properties->Set(name, base::Value::CreateNullValue());
81 } 81 }
82 82
83 void SetBoundsProperties(const gfx::Rect& bounds, 83 void SetBoundsProperties(const gfx::Rect& bounds,
84 const gfx::Size& min_size, 84 const gfx::Size& min_size,
85 const gfx::Size& max_size, 85 const gfx::Size& max_size,
86 const std::string& bounds_name, 86 const std::string& bounds_name,
87 base::DictionaryValue* window_properties) { 87 base::DictionaryValue* window_properties) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 if (content_spec.bounds.width() > 0) { 182 if (content_spec.bounds.width() > 0) {
183 combined_bounds.set_width( 183 combined_bounds.set_width(
184 content_spec.bounds.width() + frame_insets.width()); 184 content_spec.bounds.width() + frame_insets.width());
185 } 185 }
186 if (content_spec.bounds.height() > 0) { 186 if (content_spec.bounds.height() > 0) {
187 combined_bounds.set_height( 187 combined_bounds.set_height(
188 content_spec.bounds.height() + frame_insets.height()); 188 content_spec.bounds.height() + frame_insets.height());
189 } 189 }
190 190
191 // Constrain the bounds. 191 // Constrain the bounds.
192 SizeConstraints constraints( 192 extensions::SizeConstraints constraints(
193 GetCombinedWindowConstraints( 193 GetCombinedWindowConstraints(
194 window_spec.minimum_size, content_spec.minimum_size, frame_insets), 194 window_spec.minimum_size, content_spec.minimum_size, frame_insets),
195 GetCombinedWindowConstraints( 195 GetCombinedWindowConstraints(
196 window_spec.maximum_size, content_spec.maximum_size, frame_insets)); 196 window_spec.maximum_size, content_spec.maximum_size, frame_insets));
197 combined_bounds.set_size(constraints.ClampSize(combined_bounds.size())); 197 combined_bounds.set_size(constraints.ClampSize(combined_bounds.size()));
198 198
199 return combined_bounds; 199 return combined_bounds;
200 } 200 }
201 201
202 gfx::Size AppWindow::CreateParams::GetContentMinimumSize( 202 gfx::Size AppWindow::CreateParams::GetContentMinimumSize(
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 void AppWindow::OSFullscreen() { 642 void AppWindow::OSFullscreen() {
643 SetFullscreen(FULLSCREEN_TYPE_OS, true); 643 SetFullscreen(FULLSCREEN_TYPE_OS, true);
644 } 644 }
645 645
646 void AppWindow::ForcedFullscreen() { 646 void AppWindow::ForcedFullscreen() {
647 SetFullscreen(FULLSCREEN_TYPE_FORCED, true); 647 SetFullscreen(FULLSCREEN_TYPE_FORCED, true);
648 } 648 }
649 649
650 void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size, 650 void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size,
651 const gfx::Size& max_size) { 651 const gfx::Size& max_size) {
652 SizeConstraints constraints(min_size, max_size); 652 extensions::SizeConstraints constraints(min_size, max_size);
653 native_app_window_->SetContentSizeConstraints(constraints.GetMinimumSize(), 653 native_app_window_->SetContentSizeConstraints(constraints.GetMinimumSize(),
654 constraints.GetMaximumSize()); 654 constraints.GetMaximumSize());
655 655
656 gfx::Rect bounds = GetClientBounds(); 656 gfx::Rect bounds = GetClientBounds();
657 gfx::Size constrained_size = constraints.ClampSize(bounds.size()); 657 gfx::Size constrained_size = constraints.ClampSize(bounds.size());
658 if (bounds.size() != constrained_size) { 658 if (bounds.size() != constrained_size) {
659 bounds.set_size(constrained_size); 659 bounds.set_size(constrained_size);
660 bounds.Inset(-native_app_window_->GetFrameInsets()); 660 bounds.Inset(-native_app_window_->GetFrameInsets());
661 native_app_window_->SetBounds(bounds); 661 native_app_window_->SetBounds(bounds);
662 } 662 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 gfx::Size content_min_size = native_app_window_->GetContentMinimumSize(); 751 gfx::Size content_min_size = native_app_window_->GetContentMinimumSize();
752 gfx::Size content_max_size = native_app_window_->GetContentMaximumSize(); 752 gfx::Size content_max_size = native_app_window_->GetContentMaximumSize();
753 SetBoundsProperties(content_bounds, 753 SetBoundsProperties(content_bounds,
754 content_min_size, 754 content_min_size,
755 content_max_size, 755 content_max_size,
756 "innerBounds", 756 "innerBounds",
757 properties); 757 properties);
758 758
759 gfx::Insets frame_insets = native_app_window_->GetFrameInsets(); 759 gfx::Insets frame_insets = native_app_window_->GetFrameInsets();
760 gfx::Rect frame_bounds = native_app_window_->GetBounds(); 760 gfx::Rect frame_bounds = native_app_window_->GetBounds();
761 gfx::Size frame_min_size = 761 gfx::Size frame_min_size = extensions::SizeConstraints::AddFrameToConstraints(
762 SizeConstraints::AddFrameToConstraints(content_min_size, frame_insets); 762 content_min_size, frame_insets);
763 gfx::Size frame_max_size = 763 gfx::Size frame_max_size = extensions::SizeConstraints::AddFrameToConstraints(
764 SizeConstraints::AddFrameToConstraints(content_max_size, frame_insets); 764 content_max_size, frame_insets);
765 SetBoundsProperties(frame_bounds, 765 SetBoundsProperties(frame_bounds,
766 frame_min_size, 766 frame_min_size,
767 frame_max_size, 767 frame_max_size,
768 "outerBounds", 768 "outerBounds",
769 properties); 769 properties);
770 } 770 }
771 771
772 //------------------------------------------------------------------------------ 772 //------------------------------------------------------------------------------
773 // Private methods 773 // Private methods
774 774
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 if (cache->GetGeometry(extension_id(), 1065 if (cache->GetGeometry(extension_id(),
1066 params.window_key, 1066 params.window_key,
1067 &cached_bounds, 1067 &cached_bounds,
1068 &cached_screen_bounds, 1068 &cached_screen_bounds,
1069 &cached_state)) { 1069 &cached_state)) {
1070 // App window has cached screen bounds, make sure it fits on screen in 1070 // App window has cached screen bounds, make sure it fits on screen in
1071 // case the screen resolution changed. 1071 // case the screen resolution changed.
1072 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 1072 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
1073 gfx::Display display = screen->GetDisplayMatching(cached_bounds); 1073 gfx::Display display = screen->GetDisplayMatching(cached_bounds);
1074 gfx::Rect current_screen_bounds = display.work_area(); 1074 gfx::Rect current_screen_bounds = display.work_area();
1075 SizeConstraints constraints(params.GetWindowMinimumSize(gfx::Insets()), 1075 extensions::SizeConstraints constraints(
1076 params.GetWindowMaximumSize(gfx::Insets())); 1076 params.GetWindowMinimumSize(gfx::Insets()),
1077 params.GetWindowMaximumSize(gfx::Insets()));
1077 AdjustBoundsToBeVisibleOnScreen(cached_bounds, 1078 AdjustBoundsToBeVisibleOnScreen(cached_bounds,
1078 cached_screen_bounds, 1079 cached_screen_bounds,
1079 current_screen_bounds, 1080 current_screen_bounds,
1080 constraints.GetMinimumSize(), 1081 constraints.GetMinimumSize(),
1081 &params.window_spec.bounds); 1082 &params.window_spec.bounds);
1082 params.state = cached_state; 1083 params.state = cached_state;
1083 1084
1084 // Since we are restoring a cached state, reset the content bounds spec to 1085 // Since we are restoring a cached state, reset the content bounds spec to
1085 // ensure it is not used. 1086 // ensure it is not used.
1086 params.content_spec.ResetBounds(); 1087 params.content_spec.ResetBounds();
(...skipping 16 matching lines...) Expand all
1103 region.bounds.x(), 1104 region.bounds.x(),
1104 region.bounds.y(), 1105 region.bounds.y(),
1105 region.bounds.right(), 1106 region.bounds.right(),
1106 region.bounds.bottom(), 1107 region.bounds.bottom(),
1107 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 1108 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
1108 } 1109 }
1109 return sk_region; 1110 return sk_region;
1110 } 1111 }
1111 1112
1112 } // namespace apps 1113 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | apps/apps.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698