| Index: components/native_app_window/app_window_create_params.cc
|
| diff --git a/components/native_app_window/app_window_create_params.cc b/components/native_app_window/app_window_create_params.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8e882ab051945afad7a45803095d4bcc5eb2ed1e
|
| --- /dev/null
|
| +++ b/components/native_app_window/app_window_create_params.cc
|
| @@ -0,0 +1,141 @@
|
| +// Copyright 2014 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.
|
| +
|
| +#include "components/native_app_window/app_window_create_params.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "components/native_app_window/size_constraints.h"
|
| +#include "ui/gfx/geometry/insets.h"
|
| +
|
| +namespace native_app_window {
|
| +
|
| +namespace {
|
| +
|
| +// Combines the constraints of the content and window, and returns constraints
|
| +// for the window.
|
| +gfx::Size GetCombinedWindowConstraints(const gfx::Size& window_constraints,
|
| + const gfx::Size& content_constraints,
|
| + const gfx::Insets& frame_insets) {
|
| + gfx::Size combined_constraints(window_constraints);
|
| + if (content_constraints.width() > 0) {
|
| + combined_constraints.set_width(content_constraints.width() +
|
| + frame_insets.width());
|
| + }
|
| + if (content_constraints.height() > 0) {
|
| + combined_constraints.set_height(content_constraints.height() +
|
| + frame_insets.height());
|
| + }
|
| + return combined_constraints;
|
| +}
|
| +
|
| +// Combines the constraints of the content and window, and returns constraints
|
| +// for the content.
|
| +gfx::Size GetCombinedContentConstraints(const gfx::Size& window_constraints,
|
| + const gfx::Size& content_constraints,
|
| + const gfx::Insets& frame_insets) {
|
| + gfx::Size combined_constraints(content_constraints);
|
| + if (window_constraints.width() > 0) {
|
| + combined_constraints.set_width(
|
| + std::max(0, window_constraints.width() - frame_insets.width()));
|
| + }
|
| + if (window_constraints.height() > 0) {
|
| + combined_constraints.set_height(
|
| + std::max(0, window_constraints.height() - frame_insets.height()));
|
| + }
|
| + return combined_constraints;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// BoundsSpecification
|
| +
|
| +const int BoundsSpecification::kUnspecifiedPosition = INT_MIN;
|
| +
|
| +BoundsSpecification::BoundsSpecification()
|
| + : bounds(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0) {
|
| +}
|
| +
|
| +BoundsSpecification::~BoundsSpecification() {
|
| +}
|
| +
|
| +void BoundsSpecification::ResetBounds() {
|
| + bounds.SetRect(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0);
|
| +}
|
| +
|
| +// AppWindowCreateParams
|
| +
|
| +AppWindowCreateParams::AppWindowCreateParams()
|
| + : window_type(WINDOW_TYPE_DEFAULT),
|
| + frame(FRAME_CHROME),
|
| + has_frame_color(false),
|
| + active_frame_color(SK_ColorBLACK),
|
| + inactive_frame_color(SK_ColorBLACK),
|
| + alpha_enabled(false),
|
| + is_ime_window(false),
|
| + creator_process_id(0),
|
| + state(ui::SHOW_STATE_DEFAULT),
|
| + hidden(false),
|
| + resizable(true),
|
| + focused(true),
|
| + always_on_top(false),
|
| + visible_on_all_workspaces(false) {
|
| +}
|
| +
|
| +AppWindowCreateParams::~AppWindowCreateParams() {
|
| +}
|
| +
|
| +gfx::Rect AppWindowCreateParams::GetInitialWindowBounds(
|
| + const gfx::Insets& frame_insets) const {
|
| + // Combine into a single window bounds.
|
| + gfx::Rect combined_bounds(window_spec.bounds);
|
| + if (content_spec.bounds.x() != BoundsSpecification::kUnspecifiedPosition)
|
| + combined_bounds.set_x(content_spec.bounds.x() - frame_insets.left());
|
| + if (content_spec.bounds.y() != BoundsSpecification::kUnspecifiedPosition)
|
| + combined_bounds.set_y(content_spec.bounds.y() - frame_insets.top());
|
| + if (content_spec.bounds.width() > 0) {
|
| + combined_bounds.set_width(content_spec.bounds.width() +
|
| + frame_insets.width());
|
| + }
|
| + if (content_spec.bounds.height() > 0) {
|
| + combined_bounds.set_height(content_spec.bounds.height() +
|
| + frame_insets.height());
|
| + }
|
| +
|
| + // Constrain the bounds.
|
| + SizeConstraints constraints(
|
| + GetCombinedWindowConstraints(
|
| + window_spec.minimum_size, content_spec.minimum_size, frame_insets),
|
| + GetCombinedWindowConstraints(
|
| + window_spec.maximum_size, content_spec.maximum_size, frame_insets));
|
| + combined_bounds.set_size(constraints.ClampSize(combined_bounds.size()));
|
| +
|
| + return combined_bounds;
|
| +}
|
| +
|
| +gfx::Size AppWindowCreateParams::GetContentMinimumSize(
|
| + const gfx::Insets& frame_insets) const {
|
| + return GetCombinedContentConstraints(
|
| + window_spec.minimum_size, content_spec.minimum_size, frame_insets);
|
| +}
|
| +
|
| +gfx::Size AppWindowCreateParams::GetContentMaximumSize(
|
| + const gfx::Insets& frame_insets) const {
|
| + return GetCombinedContentConstraints(
|
| + window_spec.maximum_size, content_spec.maximum_size, frame_insets);
|
| +}
|
| +
|
| +gfx::Size AppWindowCreateParams::GetWindowMinimumSize(
|
| + const gfx::Insets& frame_insets) const {
|
| + return GetCombinedWindowConstraints(
|
| + window_spec.minimum_size, content_spec.minimum_size, frame_insets);
|
| +}
|
| +
|
| +gfx::Size AppWindowCreateParams::GetWindowMaximumSize(
|
| + const gfx::Insets& frame_insets) const {
|
| + return GetCombinedWindowConstraints(
|
| + window_spec.maximum_size, content_spec.maximum_size, frame_insets);
|
| +}
|
| +
|
| +} // namespace native_app_window
|
|
|