Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell_window.h" | 5 #include "apps/shell_window.h" | 
| 6 | 6 | 
| 7 #include "apps/native_app_window.h" | 7 #include "apps/native_app_window.h" | 
| 8 #include "apps/shell_window_geometry_cache.h" | 8 #include "apps/shell_window_geometry_cache.h" | 
| 9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" | 
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 using web_modal::WebContentsModalDialogManager; | 49 using web_modal::WebContentsModalDialogManager; | 
| 50 | 50 | 
| 51 namespace { | 51 namespace { | 
| 52 const int kDefaultWidth = 512; | 52 const int kDefaultWidth = 512; | 
| 53 const int kDefaultHeight = 384; | 53 const int kDefaultHeight = 384; | 
| 54 | 54 | 
| 55 } // namespace | 55 } // namespace | 
| 56 | 56 | 
| 57 namespace apps { | 57 namespace apps { | 
| 58 | 58 | 
| 59 ShellWindow::SizeConstraints::SizeConstraints() | |
| 60 : max_size_(kUnboundedSize, kUnboundedSize) { | |
| 61 } | |
| 62 | |
| 63 ShellWindow::SizeConstraints::SizeConstraints(const gfx::Size& min_size, | |
| 64 const gfx::Size& max_size) | |
| 65 : min_size_(min_size), | |
| 66 max_size_(max_size) { | |
| 67 } | |
| 68 | |
| 69 ShellWindow::SizeConstraints::~SizeConstraints() {} | |
| 70 | |
| 71 gfx::Rect ShellWindow::SizeConstraints::ClampBounds( | |
| 72 const gfx::Rect& bounds) const { | |
| 73 gfx::Rect result(bounds); | |
| 74 if (maximum_size().width() != kUnboundedSize) | |
| 75 result.set_width(std::min(result.width(), maximum_size().width())); | |
| 76 if (maximum_size().height() != kUnboundedSize) | |
| 77 result.set_height(std::min(result.height(), maximum_size().height())); | |
| 78 result.set_width(std::max(result.width(), minimum_size().width())); | |
| 
 
tapted
2013/10/14 03:17:10
I think this and the next line is just `result.Set
 
jackhou1
2013/10/14 04:13:06
SetToMax is in gfx::Size but not gfx::Rect.
 
tapted
2013/10/14 05:13:43
Ah. Drat. But... what about changing the function
 
jackhou1
2013/10/14 23:45:32
Done.
 
 | |
| 79 result.set_height(std::max(result.height(), minimum_size().height())); | |
| 80 return result; | |
| 81 } | |
| 82 | |
| 83 bool ShellWindow::SizeConstraints::HasMinimumSize() const { | |
| 84 return minimum_size().width() != kUnboundedSize || | |
| 85 minimum_size().height() != kUnboundedSize; | |
| 
 
tapted
2013/10/14 03:17:10
nit(I think): only 4 spaces of indent for these
 
jackhou1
2013/10/14 04:13:06
Done.
 
 | |
| 86 } | |
| 87 | |
| 88 bool ShellWindow::SizeConstraints::HasMaximumSize() const { | |
| 89 return maximum_size().width() != kUnboundedSize || | |
| 90 maximum_size().height() != kUnboundedSize; | |
| 91 } | |
| 92 | |
| 93 bool ShellWindow::SizeConstraints::MinAndMaxEqual() const { | |
| 94 return !minimum_size().IsEmpty() && minimum_size() == maximum_size(); | |
| 95 } | |
| 96 | |
| 97 gfx::Size ShellWindow::SizeConstraints::minimum_size() const { | |
| 98 return min_size_; | |
| 99 } | |
| 100 | |
| 101 gfx::Size ShellWindow::SizeConstraints::maximum_size() const { | |
| 102 return gfx::Size( | |
| 103 max_size_.width() == kUnboundedSize ? | |
| 104 kUnboundedSize : std::max(max_size_.width(), min_size_.width()), | |
| 105 max_size_.height() == kUnboundedSize ? | |
| 106 kUnboundedSize : std::max(max_size_.height(), min_size_.height())); | |
| 107 } | |
| 108 | |
| 59 ShellWindow::CreateParams::CreateParams() | 109 ShellWindow::CreateParams::CreateParams() | 
| 60 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), | 110 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), | 
| 61 frame(ShellWindow::FRAME_CHROME), | 111 frame(ShellWindow::FRAME_CHROME), | 
| 62 transparent_background(false), | 112 transparent_background(false), | 
| 63 bounds(INT_MIN, INT_MIN, 0, 0), | 113 bounds(INT_MIN, INT_MIN, 0, 0), | 
| 64 creator_process_id(0), | 114 creator_process_id(0), | 
| 65 state(ui::SHOW_STATE_DEFAULT), | 115 state(ui::SHOW_STATE_DEFAULT), | 
| 66 hidden(false), | 116 hidden(false), | 
| 67 resizable(true), | 117 resizable(true), | 
| 68 focused(true) {} | 118 focused(true) {} | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 96 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 146 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 
| 97 | 147 | 
| 98 web_contents->SetDelegate(this); | 148 web_contents->SetDelegate(this); | 
| 99 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 149 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 
| 100 SetDelegate(this); | 150 SetDelegate(this); | 
| 101 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); | 151 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); | 
| 102 | 152 | 
| 103 // Initialize the window | 153 // Initialize the window | 
| 104 window_type_ = params.window_type; | 154 window_type_ = params.window_type; | 
| 105 | 155 | 
| 106 gfx::Rect bounds = params.bounds; | 156 gfx::Rect bounds = params.bounds; | 
| 
 
tapted
2013/10/14 03:17:10
While we're refactoring.... I think this is the CL
 
jackhou1
2013/10/14 04:13:06
Done.
 
 | |
| 107 | 157 | 
| 108 if (bounds.width() == 0) | 158 if (bounds.width() == 0) | 
| 109 bounds.set_width(kDefaultWidth); | 159 bounds.set_width(kDefaultWidth); | 
| 110 if (bounds.height() == 0) | 160 if (bounds.height() == 0) | 
| 111 bounds.set_height(kDefaultHeight); | 161 bounds.set_height(kDefaultHeight); | 
| 112 | 162 | 
| 113 // If left and top are left undefined, the native shell window will center | 163 // If left and top are left undefined, the native shell window will center | 
| 114 // the window on the main screen in a platform-defined manner. | 164 // the window on the main screen in a platform-defined manner. | 
| 115 | 165 | 
| 116 CreateParams new_params = params; | 166 CreateParams new_params = params; | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 133 gfx::Rect current_screen_bounds = display.work_area(); | 183 gfx::Rect current_screen_bounds = display.work_area(); | 
| 134 AdjustBoundsToBeVisibleOnScreen(cached_bounds, | 184 AdjustBoundsToBeVisibleOnScreen(cached_bounds, | 
| 135 cached_screen_bounds, | 185 cached_screen_bounds, | 
| 136 current_screen_bounds, | 186 current_screen_bounds, | 
| 137 params.minimum_size, | 187 params.minimum_size, | 
| 138 &bounds); | 188 &bounds); | 
| 139 new_params.state = cached_state; | 189 new_params.state = cached_state; | 
| 140 } | 190 } | 
| 141 } | 191 } | 
| 142 | 192 | 
| 143 gfx::Size& minimum_size = new_params.minimum_size; | 193 size_constraints_ = SizeConstraints(params.minimum_size, params.maximum_size); | 
| 144 gfx::Size& maximum_size = new_params.maximum_size; | 194 new_params.bounds = size_constraints_.ClampBounds(bounds); | 
| 145 | 195 new_params.minimum_size = size_constraints_.minimum_size(); | 
| 146 // In the case that minimum size > maximum size, we consider the minimum | 196 new_params.minimum_size = size_constraints_.maximum_size(); | 
| 147 // size to be more important. | |
| 148 if (maximum_size.width() && maximum_size.width() < minimum_size.width()) | |
| 149 maximum_size.set_width(minimum_size.width()); | |
| 150 if (maximum_size.height() && maximum_size.height() < minimum_size.height()) | |
| 151 maximum_size.set_height(minimum_size.height()); | |
| 152 | |
| 153 if (maximum_size.width() && bounds.width() > maximum_size.width()) | |
| 154 bounds.set_width(maximum_size.width()); | |
| 155 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) | |
| 156 bounds.set_width(minimum_size.width()); | |
| 157 | |
| 158 if (maximum_size.height() && bounds.height() > maximum_size.height()) | |
| 159 bounds.set_height(maximum_size.height()); | |
| 160 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) | |
| 161 bounds.set_height(minimum_size.height()); | |
| 162 | |
| 163 new_params.bounds = bounds; | |
| 164 | 197 | 
| 165 native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params)); | 198 native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params)); | 
| 166 | 199 | 
| 167 if (!new_params.hidden) { | 200 if (!new_params.hidden) { | 
| 168 if (window_type_is_panel()) | 201 if (window_type_is_panel()) | 
| 169 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | 202 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | 
| 170 else | 203 else | 
| 171 GetBaseWindow()->Show(); | 204 GetBaseWindow()->Show(); | 
| 172 } | 205 } | 
| 173 | 206 | 
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 region.bounds.x(), | 688 region.bounds.x(), | 
| 656 region.bounds.y(), | 689 region.bounds.y(), | 
| 657 region.bounds.right(), | 690 region.bounds.right(), | 
| 658 region.bounds.bottom(), | 691 region.bounds.bottom(), | 
| 659 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 692 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 
| 660 } | 693 } | 
| 661 return sk_region; | 694 return sk_region; | 
| 662 } | 695 } | 
| 663 | 696 | 
| 664 } // namespace apps | 697 } // namespace apps | 
| OLD | NEW |