OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/native_app_window/app_window_create_params.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "components/native_app_window/size_constraints.h" |
| 10 #include "ui/gfx/geometry/insets.h" |
| 11 |
| 12 namespace native_app_window { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // Combines the constraints of the content and window, and returns constraints |
| 17 // for the window. |
| 18 gfx::Size GetCombinedWindowConstraints(const gfx::Size& window_constraints, |
| 19 const gfx::Size& content_constraints, |
| 20 const gfx::Insets& frame_insets) { |
| 21 gfx::Size combined_constraints(window_constraints); |
| 22 if (content_constraints.width() > 0) { |
| 23 combined_constraints.set_width(content_constraints.width() + |
| 24 frame_insets.width()); |
| 25 } |
| 26 if (content_constraints.height() > 0) { |
| 27 combined_constraints.set_height(content_constraints.height() + |
| 28 frame_insets.height()); |
| 29 } |
| 30 return combined_constraints; |
| 31 } |
| 32 |
| 33 // Combines the constraints of the content and window, and returns constraints |
| 34 // for the content. |
| 35 gfx::Size GetCombinedContentConstraints(const gfx::Size& window_constraints, |
| 36 const gfx::Size& content_constraints, |
| 37 const gfx::Insets& frame_insets) { |
| 38 gfx::Size combined_constraints(content_constraints); |
| 39 if (window_constraints.width() > 0) { |
| 40 combined_constraints.set_width( |
| 41 std::max(0, window_constraints.width() - frame_insets.width())); |
| 42 } |
| 43 if (window_constraints.height() > 0) { |
| 44 combined_constraints.set_height( |
| 45 std::max(0, window_constraints.height() - frame_insets.height())); |
| 46 } |
| 47 return combined_constraints; |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 // BoundsSpecification |
| 53 |
| 54 const int BoundsSpecification::kUnspecifiedPosition = INT_MIN; |
| 55 |
| 56 BoundsSpecification::BoundsSpecification() |
| 57 : bounds(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0) { |
| 58 } |
| 59 |
| 60 BoundsSpecification::~BoundsSpecification() { |
| 61 } |
| 62 |
| 63 void BoundsSpecification::ResetBounds() { |
| 64 bounds.SetRect(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0); |
| 65 } |
| 66 |
| 67 // AppWindowCreateParams |
| 68 |
| 69 AppWindowCreateParams::AppWindowCreateParams() |
| 70 : window_type(WINDOW_TYPE_DEFAULT), |
| 71 frame(FRAME_CHROME), |
| 72 has_frame_color(false), |
| 73 active_frame_color(SK_ColorBLACK), |
| 74 inactive_frame_color(SK_ColorBLACK), |
| 75 alpha_enabled(false), |
| 76 is_ime_window(false), |
| 77 creator_process_id(0), |
| 78 state(ui::SHOW_STATE_DEFAULT), |
| 79 hidden(false), |
| 80 resizable(true), |
| 81 focused(true), |
| 82 always_on_top(false), |
| 83 visible_on_all_workspaces(false) { |
| 84 } |
| 85 |
| 86 AppWindowCreateParams::~AppWindowCreateParams() { |
| 87 } |
| 88 |
| 89 gfx::Rect AppWindowCreateParams::GetInitialWindowBounds( |
| 90 const gfx::Insets& frame_insets) const { |
| 91 // Combine into a single window bounds. |
| 92 gfx::Rect combined_bounds(window_spec.bounds); |
| 93 if (content_spec.bounds.x() != BoundsSpecification::kUnspecifiedPosition) |
| 94 combined_bounds.set_x(content_spec.bounds.x() - frame_insets.left()); |
| 95 if (content_spec.bounds.y() != BoundsSpecification::kUnspecifiedPosition) |
| 96 combined_bounds.set_y(content_spec.bounds.y() - frame_insets.top()); |
| 97 if (content_spec.bounds.width() > 0) { |
| 98 combined_bounds.set_width(content_spec.bounds.width() + |
| 99 frame_insets.width()); |
| 100 } |
| 101 if (content_spec.bounds.height() > 0) { |
| 102 combined_bounds.set_height(content_spec.bounds.height() + |
| 103 frame_insets.height()); |
| 104 } |
| 105 |
| 106 // Constrain the bounds. |
| 107 SizeConstraints constraints( |
| 108 GetCombinedWindowConstraints( |
| 109 window_spec.minimum_size, content_spec.minimum_size, frame_insets), |
| 110 GetCombinedWindowConstraints( |
| 111 window_spec.maximum_size, content_spec.maximum_size, frame_insets)); |
| 112 combined_bounds.set_size(constraints.ClampSize(combined_bounds.size())); |
| 113 |
| 114 return combined_bounds; |
| 115 } |
| 116 |
| 117 gfx::Size AppWindowCreateParams::GetContentMinimumSize( |
| 118 const gfx::Insets& frame_insets) const { |
| 119 return GetCombinedContentConstraints( |
| 120 window_spec.minimum_size, content_spec.minimum_size, frame_insets); |
| 121 } |
| 122 |
| 123 gfx::Size AppWindowCreateParams::GetContentMaximumSize( |
| 124 const gfx::Insets& frame_insets) const { |
| 125 return GetCombinedContentConstraints( |
| 126 window_spec.maximum_size, content_spec.maximum_size, frame_insets); |
| 127 } |
| 128 |
| 129 gfx::Size AppWindowCreateParams::GetWindowMinimumSize( |
| 130 const gfx::Insets& frame_insets) const { |
| 131 return GetCombinedWindowConstraints( |
| 132 window_spec.minimum_size, content_spec.minimum_size, frame_insets); |
| 133 } |
| 134 |
| 135 gfx::Size AppWindowCreateParams::GetWindowMaximumSize( |
| 136 const gfx::Insets& frame_insets) const { |
| 137 return GetCombinedWindowConstraints( |
| 138 window_spec.maximum_size, content_spec.maximum_size, frame_insets); |
| 139 } |
| 140 |
| 141 } // namespace native_app_window |
OLD | NEW |