diff options
author | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 05:59:28 +0000 |
---|---|---|
committer | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 05:59:28 +0000 |
commit | edaebc14675b0fed0d2f07f5c3469d9a3c971bf4 (patch) | |
tree | 0ceadc689a8200bbeb28ee418063fe9a87cd5bc2 /apps | |
parent | 51a518e0c82679f770d2413a254924a4eb64892c (diff) | |
download | chromium_src-edaebc14675b0fed0d2f07f5c3469d9a3c971bf4.zip chromium_src-edaebc14675b0fed0d2f07f5c3469d9a3c971bf4.tar.gz chromium_src-edaebc14675b0fed0d2f07f5c3469d9a3c971bf4.tar.bz2 |
Implement getters for app window bounds API
This is the first patch for the new app window bounds API.
- The current Bounds class was renamed ContentBounds in order to
introduce a different Bounds class for the new API
- The properties of the innerBounds and outerBounds can now be read
- Some already deprecated bounds fields in CreateWindowOptions are no
longer documented
BUG=315471
Review URL: https://codereview.chromium.org/179393002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253729 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r-- | apps/app_window.cc | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/apps/app_window.cc b/apps/app_window.cc index ceb4bb5..443f7b6 100644 --- a/apps/app_window.cc +++ b/apps/app_window.cc @@ -51,6 +51,8 @@ using extensions::APIPermission; using web_modal::WebContentsModalDialogHost; using web_modal::WebContentsModalDialogManager; +namespace apps { + namespace { const int kDefaultWidth = 512; @@ -60,9 +62,40 @@ bool IsFullscreen(int fullscreen_types) { return fullscreen_types != apps::AppWindow::FULLSCREEN_TYPE_NONE; } -} // namespace +void SetConstraintProperty(const std::string& name, + int value, + base::DictionaryValue* bounds_properties) { + if (value != AppWindow::SizeConstraints::kUnboundedSize) + bounds_properties->SetInteger(name, value); + else + bounds_properties->Set(name, base::Value::CreateNullValue()); +} -namespace apps { +void SetBoundsProperties(const gfx::Rect& bounds, + const AppWindow::SizeConstraints& constraints, + const std::string& bounds_name, + base::DictionaryValue* window_properties) { + scoped_ptr<base::DictionaryValue> bounds_properties( + new base::DictionaryValue()); + + bounds_properties->SetInteger("left", bounds.x()); + bounds_properties->SetInteger("top", bounds.y()); + bounds_properties->SetInteger("width", bounds.width()); + bounds_properties->SetInteger("height", bounds.height()); + + gfx::Size min_size = constraints.GetMinimumSize(); + gfx::Size max_size = constraints.GetMaximumSize(); + SetConstraintProperty("minWidth", min_size.width(), bounds_properties.get()); + SetConstraintProperty( + "minHeight", min_size.height(), bounds_properties.get()); + SetConstraintProperty("maxWidth", max_size.width(), bounds_properties.get()); + SetConstraintProperty( + "maxHeight", max_size.height(), bounds_properties.get()); + + window_properties->Set(bounds_name, bounds_properties.release()); +} + +} // namespace AppWindow::SizeConstraints::SizeConstraints() : maximum_size_(kUnboundedSize, kUnboundedSize) {} @@ -609,27 +642,18 @@ void AppWindow::GetSerializedState(base::DictionaryValue* properties) const { properties->SetBoolean("minimized", native_app_window_->IsMinimized()); properties->SetBoolean("maximized", native_app_window_->IsMaximized()); properties->SetBoolean("alwaysOnTop", IsAlwaysOnTop()); - scoped_ptr<base::DictionaryValue> boundsValue(new base::DictionaryValue()); - gfx::Rect bounds = GetClientBounds(); - boundsValue->SetInteger("left", bounds.x()); - boundsValue->SetInteger("top", bounds.y()); - boundsValue->SetInteger("width", bounds.width()); - boundsValue->SetInteger("height", bounds.height()); - properties->Set("bounds", boundsValue.release()); properties->SetBoolean("hasFrameColor", native_app_window_->HasFrameColor()); properties->SetInteger("frameColor", native_app_window_->FrameColor()); - const SizeConstraints& constraints = size_constraints(); - gfx::Size min_size = constraints.GetMinimumSize(); - gfx::Size max_size = constraints.GetMaximumSize(); - if (min_size.width() != SizeConstraints::kUnboundedSize) - properties->SetInteger("minWidth", min_size.width()); - if (min_size.height() != SizeConstraints::kUnboundedSize) - properties->SetInteger("minHeight", min_size.height()); - if (max_size.width() != SizeConstraints::kUnboundedSize) - properties->SetInteger("maxWidth", max_size.width()); - if (max_size.height() != SizeConstraints::kUnboundedSize) - properties->SetInteger("maxHeight", max_size.height()); + gfx::Rect content_bounds = GetClientBounds(); + SetBoundsProperties( + content_bounds, size_constraints(), "innerBounds", properties); + + // TODO(tmdiep): Frame constraints will be implemented in a future patch. + gfx::Rect frame_bounds = native_app_window_->GetBounds(); + SizeConstraints frame_constraints; + SetBoundsProperties( + frame_bounds, frame_constraints, "outerBounds", properties); } //------------------------------------------------------------------------------ |