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/ui/views/shell_window_frame_view.h" | 5 #include "apps/ui/views/shell_window_frame_view.h" |
6 | 6 |
7 #include "apps/ui/native_app_window.h" | 7 #include "apps/ui/native_app_window.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "extensions/common/draggable_region.h" | 9 #include "extensions/common/draggable_region.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 void ShellWindowFrameView::Init(views::Widget* frame, | 54 void ShellWindowFrameView::Init(views::Widget* frame, |
55 int resize_inside_bounds_size, | 55 int resize_inside_bounds_size, |
56 int resize_outside_bounds_size, | 56 int resize_outside_bounds_size, |
57 int resize_outside_scale_for_touch, | 57 int resize_outside_scale_for_touch, |
58 int resize_area_corner_size) { | 58 int resize_area_corner_size) { |
59 frame_ = frame; | 59 frame_ = frame; |
60 resize_inside_bounds_size_ = resize_inside_bounds_size; | 60 resize_inside_bounds_size_ = resize_inside_bounds_size; |
61 resize_area_corner_size_ = resize_area_corner_size; | 61 resize_area_corner_size_ = resize_area_corner_size; |
62 | 62 |
63 if (!window_->IsFrameless()) { | 63 if (ShouldShowWindowFrame()) { |
64 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 64 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
65 close_button_ = new views::ImageButton(this); | 65 close_button_ = new views::ImageButton(this); |
66 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 66 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
67 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 67 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
68 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 68 close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
69 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); | 69 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); |
70 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 70 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
71 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); | 71 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); |
72 close_button_->SetAccessibleName( | 72 close_button_->SetAccessibleName( |
73 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 73 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 window->SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); | 120 window->SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); |
121 } | 121 } |
122 // Ensure we get resize cursors just inside our bounds as well. | 122 // Ensure we get resize cursors just inside our bounds as well. |
123 // TODO(jeremya): do we need to update these when in fullscreen/maximized? | 123 // TODO(jeremya): do we need to update these when in fullscreen/maximized? |
124 window->set_hit_test_bounds_override_inner( | 124 window->set_hit_test_bounds_override_inner( |
125 gfx::Insets(resize_inside_bounds_size_, resize_inside_bounds_size_, | 125 gfx::Insets(resize_inside_bounds_size_, resize_inside_bounds_size_, |
126 resize_inside_bounds_size_, resize_inside_bounds_size_)); | 126 resize_inside_bounds_size_, resize_inside_bounds_size_)); |
127 #endif | 127 #endif |
128 } | 128 } |
129 | 129 |
| 130 bool ShellWindowFrameView::ShouldShowWindowFrame() const { |
| 131 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 132 // Linux does not use the custom window frame. The operating system's native |
| 133 // window frame will be applied when window_->IsFrameless() is false. |
| 134 return false; |
| 135 #endif |
| 136 |
| 137 return !window_->IsFrameless(); |
| 138 } |
| 139 |
130 // views::NonClientFrameView implementation. | 140 // views::NonClientFrameView implementation. |
131 | 141 |
132 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { | 142 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { |
133 if (window_->IsFrameless() || frame_->IsFullscreen()) | 143 if (!ShouldShowWindowFrame() || frame_->IsFullscreen()) |
134 return bounds(); | 144 return bounds(); |
135 return gfx::Rect(0, kCaptionHeight, width(), | 145 return gfx::Rect(0, kCaptionHeight, width(), |
136 std::max(0, height() - kCaptionHeight)); | 146 std::max(0, height() - kCaptionHeight)); |
137 } | 147 } |
138 | 148 |
139 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds( | 149 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds( |
140 const gfx::Rect& client_bounds) const { | 150 const gfx::Rect& client_bounds) const { |
141 if (window_->IsFrameless()) { | 151 if (!ShouldShowWindowFrame()) { |
142 gfx::Rect window_bounds = client_bounds; | 152 gfx::Rect window_bounds = client_bounds; |
143 // Enforce minimum size (1, 1) in case that client_bounds is passed with | 153 // Enforce minimum size (1, 1) in case that client_bounds is passed with |
144 // empty size. This could occur when the frameless window is being | 154 // empty size. This could occur when the frameless window is being |
145 // initialized. | 155 // initialized. |
146 if (window_bounds.IsEmpty()) { | 156 if (window_bounds.IsEmpty()) { |
147 window_bounds.set_width(1); | 157 window_bounds.set_width(1); |
148 window_bounds.set_height(1); | 158 window_bounds.set_height(1); |
149 } | 159 } |
150 return window_bounds; | 160 return window_bounds; |
151 } | 161 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 resize_border, | 201 resize_border, |
192 resize_border, | 202 resize_border, |
193 resize_area_corner_size_, | 203 resize_area_corner_size_, |
194 resize_area_corner_size_, | 204 resize_area_corner_size_, |
195 can_ever_resize); | 205 can_ever_resize); |
196 if (frame_component != HTNOWHERE) | 206 if (frame_component != HTNOWHERE) |
197 return frame_component; | 207 return frame_component; |
198 | 208 |
199 // Check for possible draggable region in the client area for the frameless | 209 // Check for possible draggable region in the client area for the frameless |
200 // window. | 210 // window. |
201 if (window_->IsFrameless()) { | 211 if (!ShouldShowWindowFrame()) { |
202 SkRegion* draggable_region = window_->GetDraggableRegion(); | 212 SkRegion* draggable_region = window_->GetDraggableRegion(); |
203 if (draggable_region && draggable_region->contains(point.x(), point.y())) | 213 if (draggable_region && draggable_region->contains(point.x(), point.y())) |
204 return HTCAPTION; | 214 return HTCAPTION; |
205 } | 215 } |
206 | 216 |
207 int client_component = frame_->client_view()->NonClientHitTest(point); | 217 int client_component = frame_->client_view()->NonClientHitTest(point); |
208 if (client_component != HTNOWHERE) | 218 if (client_component != HTNOWHERE) |
209 return client_component; | 219 return client_component; |
210 | 220 |
211 // Then see if the point is within any of the window controls. | 221 // Then see if the point is within any of the window controls. |
(...skipping 24 matching lines...) Expand all Loading... |
236 // views::View implementation. | 246 // views::View implementation. |
237 | 247 |
238 gfx::Size ShellWindowFrameView::GetPreferredSize() { | 248 gfx::Size ShellWindowFrameView::GetPreferredSize() { |
239 gfx::Size pref = frame_->client_view()->GetPreferredSize(); | 249 gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
240 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | 250 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
241 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 251 return frame_->non_client_view()->GetWindowBoundsForClientBounds( |
242 bounds).size(); | 252 bounds).size(); |
243 } | 253 } |
244 | 254 |
245 void ShellWindowFrameView::Layout() { | 255 void ShellWindowFrameView::Layout() { |
246 if (window_->IsFrameless()) | 256 if (!ShouldShowWindowFrame()) |
247 return; | 257 return; |
248 gfx::Size close_size = close_button_->GetPreferredSize(); | 258 gfx::Size close_size = close_button_->GetPreferredSize(); |
249 const int kButtonOffsetY = 0; | 259 const int kButtonOffsetY = 0; |
250 const int kButtonSpacing = 1; | 260 const int kButtonSpacing = 1; |
251 const int kRightMargin = 3; | 261 const int kRightMargin = 3; |
252 | 262 |
253 close_button_->SetBounds( | 263 close_button_->SetBounds( |
254 width() - kRightMargin - close_size.width(), | 264 width() - kRightMargin - close_size.width(), |
255 kButtonOffsetY, | 265 kButtonOffsetY, |
256 close_size.width(), | 266 close_size.width(), |
(...skipping 26 matching lines...) Expand all Loading... |
283 | 293 |
284 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); | 294 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); |
285 minimize_button_->SetBounds( | 295 minimize_button_->SetBounds( |
286 maximize_button_->x() - kButtonSpacing - minimize_size.width(), | 296 maximize_button_->x() - kButtonSpacing - minimize_size.width(), |
287 kButtonOffsetY, | 297 kButtonOffsetY, |
288 minimize_size.width(), | 298 minimize_size.width(), |
289 minimize_size.height()); | 299 minimize_size.height()); |
290 } | 300 } |
291 | 301 |
292 void ShellWindowFrameView::OnPaint(gfx::Canvas* canvas) { | 302 void ShellWindowFrameView::OnPaint(gfx::Canvas* canvas) { |
293 if (window_->IsFrameless()) | 303 if (!ShouldShowWindowFrame()) |
294 return; | 304 return; |
295 | 305 |
296 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 306 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
297 if (ShouldPaintAsActive()) { | 307 if (ShouldPaintAsActive()) { |
298 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 308 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
299 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 309 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
300 } else { | 310 } else { |
301 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 311 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
302 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); | 312 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); |
303 } | 313 } |
(...skipping 14 matching lines...) Expand all Loading... |
318 path.close(); | 328 path.close(); |
319 canvas->DrawPath(path, paint); | 329 canvas->DrawPath(path, paint); |
320 } | 330 } |
321 | 331 |
322 const char* ShellWindowFrameView::GetClassName() const { | 332 const char* ShellWindowFrameView::GetClassName() const { |
323 return kViewClassName; | 333 return kViewClassName; |
324 } | 334 } |
325 | 335 |
326 gfx::Size ShellWindowFrameView::GetMinimumSize() { | 336 gfx::Size ShellWindowFrameView::GetMinimumSize() { |
327 gfx::Size min_size = frame_->client_view()->GetMinimumSize(); | 337 gfx::Size min_size = frame_->client_view()->GetMinimumSize(); |
328 if (window_->IsFrameless()) | 338 if (!ShouldShowWindowFrame()) |
329 return min_size; | 339 return min_size; |
330 | 340 |
331 // Ensure we can display the top of the caption area. | 341 // Ensure we can display the top of the caption area. |
332 gfx::Rect client_bounds = GetBoundsForClientView(); | 342 gfx::Rect client_bounds = GetBoundsForClientView(); |
333 min_size.Enlarge(0, client_bounds.y()); | 343 min_size.Enlarge(0, client_bounds.y()); |
334 // Ensure we have enough space for the window icon and buttons. We allow | 344 // Ensure we have enough space for the window icon and buttons. We allow |
335 // the title string to collapse to zero width. | 345 // the title string to collapse to zero width. |
336 int closeButtonOffsetX = | 346 int closeButtonOffsetX = |
337 (kCaptionHeight - close_button_->height()) / 2; | 347 (kCaptionHeight - close_button_->height()) / 2; |
338 int header_width = close_button_->width() + closeButtonOffsetX * 2; | 348 int header_width = close_button_->width() + closeButtonOffsetX * 2; |
(...skipping 12 matching lines...) Expand all Loading... |
351 if (max_size.height()) | 361 if (max_size.height()) |
352 max_size.Enlarge(0, height() - client_size.height()); | 362 max_size.Enlarge(0, height() - client_size.height()); |
353 | 363 |
354 return max_size; | 364 return max_size; |
355 } | 365 } |
356 | 366 |
357 // views::ButtonListener implementation. | 367 // views::ButtonListener implementation. |
358 | 368 |
359 void ShellWindowFrameView::ButtonPressed(views::Button* sender, | 369 void ShellWindowFrameView::ButtonPressed(views::Button* sender, |
360 const ui::Event& event) { | 370 const ui::Event& event) { |
361 DCHECK(!window_->IsFrameless()); | 371 DCHECK(ShouldShowWindowFrame()); |
362 if (sender == close_button_) | 372 if (sender == close_button_) |
363 frame_->Close(); | 373 frame_->Close(); |
364 else if (sender == maximize_button_) | 374 else if (sender == maximize_button_) |
365 frame_->Maximize(); | 375 frame_->Maximize(); |
366 else if (sender == restore_button_) | 376 else if (sender == restore_button_) |
367 frame_->Restore(); | 377 frame_->Restore(); |
368 else if (sender == minimize_button_) | 378 else if (sender == minimize_button_) |
369 frame_->Minimize(); | 379 frame_->Minimize(); |
370 } | 380 } |
371 | 381 |
372 } // namespace apps | 382 } // namespace apps |
OLD | NEW |