OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/window/custom_frame_view.h" | 5 #include "ui/views/window/custom_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "ui/views/window/frame_background.h" | 24 #include "ui/views/window/frame_background.h" |
25 #include "ui/views/window/window_resources.h" | 25 #include "ui/views/window/window_resources.h" |
26 #include "ui/views/window/window_shape.h" | 26 #include "ui/views/window/window_shape.h" |
27 | 27 |
28 #if defined(USE_AURA) | 28 #if defined(USE_AURA) |
29 #include "ui/views/widget/native_widget_aura.h" | 29 #include "ui/views/widget/native_widget_aura.h" |
30 #elif defined(OS_WIN) | 30 #elif defined(OS_WIN) |
31 #include "ui/views/widget/native_widget_win.h" | 31 #include "ui/views/widget/native_widget_win.h" |
32 #endif | 32 #endif |
33 | 33 |
34 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
35 #include "ui/views/linux_ui/linux_ui.h" | |
Ben Goodger (Google)
2014/01/09 23:03:27
Hrm... I would actually like to not have this type
Matt Giuca
2014/01/10 01:07:50
Is the style used by OpaqueBrowserFrameView (havin
| |
36 #endif | |
37 | |
34 namespace views { | 38 namespace views { |
35 | 39 |
36 namespace { | 40 namespace { |
37 | 41 |
38 // The frame border is only visible in restored mode and is hardcoded to 4 px on | 42 // The frame border is only visible in restored mode and is hardcoded to 4 px on |
39 // each side regardless of the system window border size. | 43 // each side regardless of the system window border size. |
40 const int kFrameBorderThickness = 4; | 44 const int kFrameBorderThickness = 4; |
41 // In the window corners, the resize areas don't actually expand bigger, but the | 45 // In the window corners, the resize areas don't actually expand bigger, but the |
42 // 16 px at the end of each edge triggers diagonal resizing. | 46 // 16 px at the end of each edge triggers diagonal resizing. |
43 const int kResizeAreaCornerSize = 16; | 47 const int kResizeAreaCornerSize = 16; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), | 183 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), |
180 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, | 184 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, |
181 frame_->widget_delegate()->CanResize()); | 185 frame_->widget_delegate()->CanResize()); |
182 // Fall back to the caption if no other component matches. | 186 // Fall back to the caption if no other component matches. |
183 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 187 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
184 } | 188 } |
185 | 189 |
186 void CustomFrameView::GetWindowMask(const gfx::Size& size, | 190 void CustomFrameView::GetWindowMask(const gfx::Size& size, |
187 gfx::Path* window_mask) { | 191 gfx::Path* window_mask) { |
188 DCHECK(window_mask); | 192 DCHECK(window_mask); |
189 if (frame_->IsMaximized()) | 193 if (frame_->IsMaximized() || !ShouldShowTitleBarAndBorder()) |
190 return; | 194 return; |
191 | 195 |
192 GetDefaultWindowMask(size, window_mask); | 196 GetDefaultWindowMask(size, window_mask); |
193 } | 197 } |
194 | 198 |
195 void CustomFrameView::ResetWindowControls() { | 199 void CustomFrameView::ResetWindowControls() { |
196 restore_button_->SetState(CustomButton::STATE_NORMAL); | 200 restore_button_->SetState(CustomButton::STATE_NORMAL); |
197 minimize_button_->SetState(CustomButton::STATE_NORMAL); | 201 minimize_button_->SetState(CustomButton::STATE_NORMAL); |
198 maximize_button_->SetState(CustomButton::STATE_NORMAL); | 202 maximize_button_->SetState(CustomButton::STATE_NORMAL); |
199 // The close button isn't affected by this constraint. | 203 // The close button isn't affected by this constraint. |
200 } | 204 } |
201 | 205 |
202 void CustomFrameView::UpdateWindowIcon() { | 206 void CustomFrameView::UpdateWindowIcon() { |
203 if (window_icon_) | 207 if (window_icon_) |
204 window_icon_->SchedulePaint(); | 208 window_icon_->SchedulePaint(); |
205 } | 209 } |
206 | 210 |
207 void CustomFrameView::UpdateWindowTitle() { | 211 void CustomFrameView::UpdateWindowTitle() { |
208 SchedulePaintInRect(title_bounds_); | 212 SchedulePaintInRect(title_bounds_); |
209 } | 213 } |
210 | 214 |
211 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
212 // CustomFrameView, View overrides: | 216 // CustomFrameView, View overrides: |
213 | 217 |
214 void CustomFrameView::OnPaint(gfx::Canvas* canvas) { | 218 void CustomFrameView::OnPaint(gfx::Canvas* canvas) { |
219 if (!ShouldShowTitleBarAndBorder()) | |
220 return; | |
221 | |
215 if (frame_->IsMaximized()) | 222 if (frame_->IsMaximized()) |
216 PaintMaximizedFrameBorder(canvas); | 223 PaintMaximizedFrameBorder(canvas); |
217 else | 224 else |
218 PaintRestoredFrameBorder(canvas); | 225 PaintRestoredFrameBorder(canvas); |
219 PaintTitleBar(canvas); | 226 PaintTitleBar(canvas); |
220 if (ShouldShowClientEdge()) | 227 if (ShouldShowClientEdge()) |
221 PaintRestoredClientEdge(canvas); | 228 PaintRestoredClientEdge(canvas); |
222 } | 229 } |
223 | 230 |
224 void CustomFrameView::Layout() { | 231 void CustomFrameView::Layout() { |
225 LayoutWindowControls(); | 232 if (ShouldShowTitleBarAndBorder()) { |
226 LayoutTitleBar(); | 233 LayoutWindowControls(); |
234 LayoutTitleBar(); | |
235 } | |
236 | |
227 LayoutClientView(); | 237 LayoutClientView(); |
228 } | 238 } |
229 | 239 |
230 gfx::Size CustomFrameView::GetPreferredSize() { | 240 gfx::Size CustomFrameView::GetPreferredSize() { |
231 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 241 return frame_->non_client_view()->GetWindowBoundsForClientBounds( |
232 gfx::Rect(frame_->client_view()->GetPreferredSize())).size(); | 242 gfx::Rect(frame_->client_view()->GetPreferredSize())).size(); |
233 } | 243 } |
234 | 244 |
235 gfx::Size CustomFrameView::GetMinimumSize() { | 245 gfx::Size CustomFrameView::GetMinimumSize() { |
236 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 246 return frame_->non_client_view()->GetWindowBoundsForClientBounds( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 // When the icon is shorter than the minimum space we reserve for the caption | 326 // When the icon is shorter than the minimum space we reserve for the caption |
317 // button, we vertically center it. We want to bias rounding to put extra | 327 // button, we vertically center it. We want to bias rounding to put extra |
318 // space above the icon, since the 3D edge (+ client edge, for restored | 328 // space above the icon, since the 3D edge (+ client edge, for restored |
319 // windows) below looks (to the eye) more like additional space than does the | 329 // windows) below looks (to the eye) more like additional space than does the |
320 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. | 330 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. |
321 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - | 331 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - |
322 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; | 332 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; |
323 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); | 333 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); |
324 } | 334 } |
325 | 335 |
336 bool CustomFrameView::ShouldShowTitleBarAndBorder() const { | |
337 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
338 // On Ubuntu Unity, if the window is maximized, the system will provide a | |
339 // title and caption buttons, so we should not add our own. | |
Ben Goodger (Google)
2014/01/10 16:41:50
is this true of all frame types within views? if s
Matt Giuca
2014/01/17 01:29:51
OK, I have added a ViewsDelegate method for this.
| |
340 views::LinuxUI* ui = views::LinuxUI::instance(); | |
341 return !(frame_->IsMaximized() && ui && ui->UnityIsRunning()); | |
342 #endif | |
343 | |
344 return true; | |
345 } | |
346 | |
326 bool CustomFrameView::ShouldShowClientEdge() const { | 347 bool CustomFrameView::ShouldShowClientEdge() const { |
327 return !frame_->IsMaximized(); | 348 return !frame_->IsMaximized() && ShouldShowTitleBarAndBorder(); |
328 } | 349 } |
329 | 350 |
330 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { | 351 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { |
331 frame_background_->set_frame_color(GetFrameColor()); | 352 frame_background_->set_frame_color(GetFrameColor()); |
332 const gfx::ImageSkia* frame_image = GetFrameImage(); | 353 const gfx::ImageSkia* frame_image = GetFrameImage(); |
333 frame_background_->set_theme_image(frame_image); | 354 frame_background_->set_theme_image(frame_image); |
334 frame_background_->set_top_area_height(frame_image->height()); | 355 frame_background_->set_top_area_height(frame_image->height()); |
335 | 356 |
336 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 357 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
337 | 358 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 // midline rather than below. This compensates for how the icon is already | 563 // midline rather than below. This compensates for how the icon is already |
543 // biased downwards (see IconBounds()) and helps prevent descenders on the | 564 // biased downwards (see IconBounds()) and helps prevent descenders on the |
544 // title from overlapping the 3D edge at the bottom of the titlebar. | 565 // title from overlapping the 3D edge at the bottom of the titlebar. |
545 title_bounds_.SetRect(title_x, | 566 title_bounds_.SetRect(title_x, |
546 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), | 567 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), |
547 std::max(0, minimize_button_->x() - kTitleCaptionSpacing - | 568 std::max(0, minimize_button_->x() - kTitleCaptionSpacing - |
548 title_x), title_height); | 569 title_x), title_height); |
549 } | 570 } |
550 | 571 |
551 void CustomFrameView::LayoutClientView() { | 572 void CustomFrameView::LayoutClientView() { |
573 if (!ShouldShowTitleBarAndBorder()) { | |
574 client_view_bounds_ = bounds(); | |
575 return; | |
576 } | |
577 | |
552 int top_height = NonClientTopBorderHeight(); | 578 int top_height = NonClientTopBorderHeight(); |
553 int border_thickness = NonClientBorderThickness(); | 579 int border_thickness = NonClientBorderThickness(); |
554 client_view_bounds_.SetRect(border_thickness, top_height, | 580 client_view_bounds_.SetRect(border_thickness, top_height, |
555 std::max(0, width() - (2 * border_thickness)), | 581 std::max(0, width() - (2 * border_thickness)), |
556 std::max(0, height() - top_height - border_thickness)); | 582 std::max(0, height() - top_height - border_thickness)); |
557 } | 583 } |
558 | 584 |
559 ImageButton* CustomFrameView::InitWindowCaptionButton( | 585 ImageButton* CustomFrameView::InitWindowCaptionButton( |
560 int accessibility_string_id, | 586 int accessibility_string_id, |
561 int normal_image_id, | 587 int normal_image_id, |
562 int hot_image_id, | 588 int hot_image_id, |
563 int pushed_image_id) { | 589 int pushed_image_id) { |
564 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 590 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
565 ImageButton* button = new ImageButton(this); | 591 ImageButton* button = new ImageButton(this); |
566 button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id)); | 592 button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id)); |
567 button->SetImage(CustomButton::STATE_NORMAL, | 593 button->SetImage(CustomButton::STATE_NORMAL, |
568 rb.GetImageNamed(normal_image_id).ToImageSkia()); | 594 rb.GetImageNamed(normal_image_id).ToImageSkia()); |
569 button->SetImage(CustomButton::STATE_HOVERED, | 595 button->SetImage(CustomButton::STATE_HOVERED, |
570 rb.GetImageNamed(hot_image_id).ToImageSkia()); | 596 rb.GetImageNamed(hot_image_id).ToImageSkia()); |
571 button->SetImage(CustomButton::STATE_PRESSED, | 597 button->SetImage(CustomButton::STATE_PRESSED, |
572 rb.GetImageNamed(pushed_image_id).ToImageSkia()); | 598 rb.GetImageNamed(pushed_image_id).ToImageSkia()); |
573 AddChildView(button); | 599 AddChildView(button); |
574 return button; | 600 return button; |
575 } | 601 } |
576 | 602 |
577 } // namespace views | 603 } // namespace views |
OLD | NEW |