diff options
| author | jeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 07:23:20 +0000 |
|---|---|---|
| committer | jeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 07:23:20 +0000 |
| commit | f8c3aead7e7812724f1c21bb697464aca0edd89b (patch) | |
| tree | 3ff4e4f79bffde7294991cb71c28ba7d3ef21c8e | |
| parent | 6bba4d94f16790cdd0a0ef66b8d5d5c87ae51c2b (diff) | |
| download | chromium_src-f8c3aead7e7812724f1c21bb697464aca0edd89b.zip chromium_src-f8c3aead7e7812724f1c21bb697464aca0edd89b.tar.gz chromium_src-f8c3aead7e7812724f1c21bb697464aca0edd89b.tar.bz2 | |
Allow platform apps to specify a maximum size for the shell container.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/9452008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124380 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/ui/views/extensions/shell_window_views.cc | 15 | ||||
| -rw-r--r-- | chrome/common/extensions/extension.cc | 26 | ||||
| -rw-r--r-- | chrome/common/extensions/extension.h | 17 | ||||
| -rw-r--r-- | chrome/common/extensions/extension_constants.cc | 2 | ||||
| -rw-r--r-- | chrome/common/extensions/extension_constants.h | 2 | ||||
| -rw-r--r-- | chrome/common/extensions/extension_manifests_unittest.cc | 4 | ||||
| -rw-r--r-- | chrome/test/data/extensions/manifest_tests/launch_container_invalid_size_constraints.json | 15 | ||||
| -rw-r--r-- | ui/views/view.cc | 4 | ||||
| -rw-r--r-- | ui/views/view.h | 4 | ||||
| -rw-r--r-- | ui/views/widget/native_widget_delegate.h | 3 | ||||
| -rw-r--r-- | ui/views/widget/native_widget_win.cc | 11 | ||||
| -rw-r--r-- | ui/views/widget/widget.cc | 4 | ||||
| -rw-r--r-- | ui/views/widget/widget.h | 1 | ||||
| -rw-r--r-- | ui/views/window/non_client_view.cc | 4 | ||||
| -rw-r--r-- | ui/views/window/non_client_view.h | 3 |
15 files changed, 106 insertions, 9 deletions
diff --git a/chrome/browser/ui/views/extensions/shell_window_views.cc b/chrome/browser/ui/views/extensions/shell_window_views.cc index a53733f..524a37e 100644 --- a/chrome/browser/ui/views/extensions/shell_window_views.cc +++ b/chrome/browser/ui/views/extensions/shell_window_views.cc @@ -40,13 +40,16 @@ class ShellWindowFrameView : public views::NonClientFrameView { virtual void ResetWindowControls() OVERRIDE {} virtual void UpdateWindowIcon() OVERRIDE {} virtual gfx::Size GetMinimumSize() OVERRIDE; + virtual gfx::Size GetMaximumSize() OVERRIDE; void set_min_size(gfx::Size size) { min_size_ = size; } + void set_max_size(gfx::Size size) { max_size_ = size; } private: DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView); gfx::Size min_size_; + gfx::Size max_size_; }; ShellWindowFrameView::ShellWindowFrameView(): min_size_() { @@ -100,6 +103,9 @@ gfx::Size ShellWindowFrameView::GetMinimumSize() { return min_size_; } +gfx::Size ShellWindowFrameView::GetMaximumSize() { + return max_size_; +} ShellWindowViews::ShellWindowViews(ExtensionHost* host) : ShellWindow(host) { @@ -150,9 +156,12 @@ views::View* ShellWindowViews::GetContentsView() { views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView() { ShellWindowFrameView* frame_view = new ShellWindowFrameView(); - gfx::Size size(host_->extension()->launch_min_width(), - host_->extension()->launch_min_height()); - frame_view->set_min_size(size); + gfx::Size min_size(host_->extension()->launch_min_width(), + host_->extension()->launch_min_height()); + gfx::Size max_size(host_->extension()->launch_max_width(), + host_->extension()->launch_max_height()); + frame_view->set_min_size(min_size); + frame_view->set_max_size(max_size); return frame_view; } diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 04eb7df..dd9fb92 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1250,6 +1250,18 @@ bool Extension::LoadLaunchContainer(string16* error) { can_specify_size_range, error)) return false; + if (!ReadLaunchDimension(manifest_, + keys::kLaunchMaxWidth, + &launch_max_width_, + can_specify_size_range, + error)) + return false; + if (!ReadLaunchDimension(manifest_, + keys::kLaunchMaxHeight, + &launch_max_height_, + can_specify_size_range, + error)) + return false; if (launch_container() == extension_misc::LAUNCH_SHELL) { if (!manifest_->Get(keys::kLaunchWidth, &temp)) { @@ -1264,6 +1276,18 @@ bool Extension::LoadLaunchContainer(string16* error) { keys::kLaunchHeight); return false; } + if (launch_max_width_ > 0 && launch_max_width_ < launch_min_width_) { + *error = ExtensionErrorUtils::FormatErrorMessageUTF16( + errors::kInvalidLaunchValue, + keys::kLaunchMaxWidth); + return false; + } + if (launch_max_height_ > 0 && launch_max_height_ < launch_min_height_) { + *error = ExtensionErrorUtils::FormatErrorMessageUTF16( + errors::kInvalidLaunchValue, + keys::kLaunchMaxHeight); + return false; + } } return true; @@ -1511,6 +1535,8 @@ Extension::Extension(const FilePath& path, launch_height_(0), launch_min_width_(0), launch_min_height_(0), + launch_max_width_(0), + launch_max_height_(0), wants_file_access_(false), creation_flags_(0) { DCHECK(path.empty() || path.IsAbsolute()); diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index fd224f2..0f789eb 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -611,13 +611,21 @@ class Extension : public base::RefCountedThreadSafe<Extension> { return launch_container_; } int launch_width() const { - return std::max(launch_min_width_, launch_width_); + return std::max(launch_min_width_, + launch_max_width_ ? + std::min(launch_max_width_, launch_width_) : + launch_width_); } int launch_height() const { - return std::max(launch_min_height_, launch_height_); + return std::max(launch_min_height_, + launch_max_height_ ? + std::min(launch_max_height_, launch_height_) : + launch_height_); } int launch_min_width() const { return launch_min_width_; } int launch_min_height() const { return launch_min_height_; } + int launch_max_width() const { return launch_max_width_; } + int launch_max_height() const { return launch_max_height_; } // Theme-related. bool is_theme() const; @@ -914,9 +922,12 @@ class Extension : public base::RefCountedThreadSafe<Extension> { int launch_width_; int launch_height_; - // The minimum size of the container. Only respected for the shell container. + // The minimum and maximum size of the container. Only respected for the + // shell container. int launch_min_width_; int launch_min_height_; + int launch_max_width_; + int launch_max_height_; // The Omnibox keyword for this extension, or empty if there is none. std::string omnibox_keyword_; diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 38ece13..c50c2e5 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -58,6 +58,8 @@ const char kLaunchContainer[] = "app.launch.container"; const char kLaunchHeight[] = "app.launch.height"; const char kLaunchLocalPath[] = "app.launch.local_path"; const char kLaunchWebURL[] = "app.launch.web_url"; +const char kLaunchMaxHeight[] = "app.launch.max_height"; +const char kLaunchMaxWidth[] = "app.launch.max_width"; const char kLaunchMinHeight[] = "app.launch.min_height"; const char kLaunchMinWidth[] = "app.launch.min_width"; const char kLaunchWidth[] = "app.launch.width"; diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h index 0b14672..ca87caa 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -59,6 +59,8 @@ namespace extension_manifest_keys { extern const char kLaunchContainer[]; extern const char kLaunchHeight[]; extern const char kLaunchLocalPath[]; + extern const char kLaunchMaxHeight[]; + extern const char kLaunchMaxWidth[]; extern const char kLaunchMinHeight[]; extern const char kLaunchMinWidth[]; extern const char kLaunchWebURL[]; diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc index bf6cc87..e1d108f 100644 --- a/chrome/common/extensions/extension_manifests_unittest.cc +++ b/chrome/common/extensions/extension_manifests_unittest.cc @@ -458,6 +458,10 @@ TEST_F(ExtensionManifestTest, AppLaunchContainer) { ExtensionErrorUtils::FormatErrorMessage( errors::kInvalidLaunchValue, keys::kLaunchWidth)); + LoadAndExpectError("launch_container_invalid_size_constraints.json", + ExtensionErrorUtils::FormatErrorMessage( + errors::kInvalidLaunchValue, + keys::kLaunchMaxWidth)); } TEST_F(ExtensionManifestTest, PlatformAppLaunchContainer) { diff --git a/chrome/test/data/extensions/manifest_tests/launch_container_invalid_size_constraints.json b/chrome/test/data/extensions/manifest_tests/launch_container_invalid_size_constraints.json new file mode 100644 index 0000000..f310552 --- /dev/null +++ b/chrome/test/data/extensions/manifest_tests/launch_container_invalid_size_constraints.json @@ -0,0 +1,15 @@ +{ + "name": "test", + "version": "1", + "platform_app": true, + "app": { + "launch": { + "container": "shell", + "local_path": "hot.html", + "width": 250, + "height": 250, + "min_width": 100, + "max_width": 50 + } + } +} diff --git a/ui/views/view.cc b/ui/views/view.cc index 8b356b2..526b45a 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -381,6 +381,10 @@ gfx::Size View::GetMinimumSize() { return GetPreferredSize(); } +gfx::Size View::GetMaximumSize() { + return gfx::Size(); +} + int View::GetHeightForWidth(int w) { if (layout_manager_.get()) return layout_manager_->GetPreferredHeightForWidth(this, w); diff --git a/ui/views/view.h b/ui/views/view.h index a203b49..c197033 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -235,6 +235,10 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // GetPreferredSize. virtual gfx::Size GetMinimumSize(); + // Gets the maximum size of the view. Currently only used for sizing shell + // windows. + virtual gfx::Size GetMaximumSize(); + // Return the height necessary to display this view with the provided width. // View's implementation returns the value from getPreferredSize.cy. // Override if your View's preferred height depends upon the width (such diff --git a/ui/views/widget/native_widget_delegate.h b/ui/views/widget/native_widget_delegate.h index 6bbef31..4fac0b0 100644 --- a/ui/views/widget/native_widget_delegate.h +++ b/ui/views/widget/native_widget_delegate.h @@ -69,6 +69,9 @@ class VIEWS_EXPORT NativeWidgetDelegate { // Returns the smallest size the window can be resized to by the user. virtual gfx::Size GetMinimumSize() = 0; + // Returns the largest size the window can be resized to by the user. + virtual gfx::Size GetMaximumSize() = 0; + // Called when the NativeWidget changed size to |new_size|. virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) = 0; diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index e16d757..5f61811 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -1384,17 +1384,24 @@ LRESULT NativeWidgetWin::OnGetObject(UINT uMsg, void NativeWidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { gfx::Size min_window_size(delegate_->GetMinimumSize()); - // Add the native frame border size to the minimum size if the view reports - // its size as the client size. + gfx::Size max_window_size(delegate_->GetMaximumSize()); + // Add the native frame border size to the minimum and maximum size if the + // view reports its size as the client size. if (WidgetSizeIsClientSize()) { CRect client_rect, window_rect; GetClientRect(&client_rect); GetWindowRect(&window_rect); window_rect -= client_rect; min_window_size.Enlarge(window_rect.Width(), window_rect.Height()); + if (!max_window_size.IsEmpty()) + max_window_size.Enlarge(window_rect.Width(), window_rect.Height()); } minmax_info->ptMinTrackSize.x = min_window_size.width(); minmax_info->ptMinTrackSize.y = min_window_size.height(); + if (!max_window_size.IsEmpty()) { + minmax_info->ptMaxTrackSize.x = max_window_size.width(); + minmax_info->ptMaxTrackSize.y = max_window_size.height(); + } SetMsgHandled(FALSE); } diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index 6073a89..6a2fdc9 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -968,6 +968,10 @@ gfx::Size Widget::GetMinimumSize() { return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); } +gfx::Size Widget::GetMaximumSize() { + return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); +} + void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { root_view_->SetSize(new_size); diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h index 265ae36..527914a 100644 --- a/ui/views/widget/widget.h +++ b/ui/views/widget/widget.h @@ -616,6 +616,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, virtual void OnNativeWidgetDestroying() OVERRIDE; virtual void OnNativeWidgetDestroyed() OVERRIDE; virtual gfx::Size GetMinimumSize() OVERRIDE; + virtual gfx::Size GetMaximumSize() OVERRIDE; virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE; virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE; virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE; diff --git a/ui/views/window/non_client_view.cc b/ui/views/window/non_client_view.cc index 9d37b5f..f4a710e 100644 --- a/ui/views/window/non_client_view.cc +++ b/ui/views/window/non_client_view.cc @@ -129,6 +129,10 @@ gfx::Size NonClientView::GetMinimumSize() { return frame_view_->GetMinimumSize(); } +gfx::Size NonClientView::GetMaximumSize() { + return frame_view_->GetMaximumSize(); +} + void NonClientView::Layout() { LayoutFrameView(); diff --git a/ui/views/window/non_client_view.h b/ui/views/window/non_client_view.h index 55ad896..ebf661e 100644 --- a/ui/views/window/non_client_view.h +++ b/ui/views/window/non_client_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -201,6 +201,7 @@ class VIEWS_EXPORT NonClientView : public View { // NonClientView, View overrides: virtual gfx::Size GetPreferredSize() OVERRIDE; virtual gfx::Size GetMinimumSize() OVERRIDE; + virtual gfx::Size GetMaximumSize() OVERRIDE; virtual void Layout() OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual std::string GetClassName() const OVERRIDE; |
