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" |
11 #include "grit/ui_strings.h" | 11 #include "grit/ui_strings.h" |
12 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/font.h" | 16 #include "ui/gfx/font.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
19 #include "ui/views/color_constants.h" | 19 #include "ui/views/color_constants.h" |
20 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/views_delegate.h" |
21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
22 #include "ui/views/widget/widget_delegate.h" | 23 #include "ui/views/widget/widget_delegate.h" |
23 #include "ui/views/window/client_view.h" | 24 #include "ui/views/window/client_view.h" |
24 #include "ui/views/window/frame_background.h" | 25 #include "ui/views/window/frame_background.h" |
25 #include "ui/views/window/window_resources.h" | 26 #include "ui/views/window/window_resources.h" |
26 #include "ui/views/window/window_shape.h" | 27 #include "ui/views/window/window_shape.h" |
27 | 28 |
28 #if defined(USE_AURA) | 29 #if defined(USE_AURA) |
29 #include "ui/views/widget/native_widget_aura.h" | 30 #include "ui/views/widget/native_widget_aura.h" |
30 #elif defined(OS_WIN) | 31 #elif defined(OS_WIN) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), | 180 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), |
180 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, | 181 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, |
181 frame_->widget_delegate()->CanResize()); | 182 frame_->widget_delegate()->CanResize()); |
182 // Fall back to the caption if no other component matches. | 183 // Fall back to the caption if no other component matches. |
183 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 184 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
184 } | 185 } |
185 | 186 |
186 void CustomFrameView::GetWindowMask(const gfx::Size& size, | 187 void CustomFrameView::GetWindowMask(const gfx::Size& size, |
187 gfx::Path* window_mask) { | 188 gfx::Path* window_mask) { |
188 DCHECK(window_mask); | 189 DCHECK(window_mask); |
189 if (frame_->IsMaximized()) | 190 if (frame_->IsMaximized() || !ShouldShowTitleBarAndBorder()) |
190 return; | 191 return; |
191 | 192 |
192 GetDefaultWindowMask(size, window_mask); | 193 GetDefaultWindowMask(size, window_mask); |
193 } | 194 } |
194 | 195 |
195 void CustomFrameView::ResetWindowControls() { | 196 void CustomFrameView::ResetWindowControls() { |
196 restore_button_->SetState(CustomButton::STATE_NORMAL); | 197 restore_button_->SetState(CustomButton::STATE_NORMAL); |
197 minimize_button_->SetState(CustomButton::STATE_NORMAL); | 198 minimize_button_->SetState(CustomButton::STATE_NORMAL); |
198 maximize_button_->SetState(CustomButton::STATE_NORMAL); | 199 maximize_button_->SetState(CustomButton::STATE_NORMAL); |
199 // The close button isn't affected by this constraint. | 200 // The close button isn't affected by this constraint. |
200 } | 201 } |
201 | 202 |
202 void CustomFrameView::UpdateWindowIcon() { | 203 void CustomFrameView::UpdateWindowIcon() { |
203 if (window_icon_) | 204 if (window_icon_) |
204 window_icon_->SchedulePaint(); | 205 window_icon_->SchedulePaint(); |
205 } | 206 } |
206 | 207 |
207 void CustomFrameView::UpdateWindowTitle() { | 208 void CustomFrameView::UpdateWindowTitle() { |
208 SchedulePaintInRect(title_bounds_); | 209 SchedulePaintInRect(title_bounds_); |
209 } | 210 } |
210 | 211 |
211 /////////////////////////////////////////////////////////////////////////////// | 212 /////////////////////////////////////////////////////////////////////////////// |
212 // CustomFrameView, View overrides: | 213 // CustomFrameView, View overrides: |
213 | 214 |
214 void CustomFrameView::OnPaint(gfx::Canvas* canvas) { | 215 void CustomFrameView::OnPaint(gfx::Canvas* canvas) { |
| 216 if (!ShouldShowTitleBarAndBorder()) |
| 217 return; |
| 218 |
215 if (frame_->IsMaximized()) | 219 if (frame_->IsMaximized()) |
216 PaintMaximizedFrameBorder(canvas); | 220 PaintMaximizedFrameBorder(canvas); |
217 else | 221 else |
218 PaintRestoredFrameBorder(canvas); | 222 PaintRestoredFrameBorder(canvas); |
219 PaintTitleBar(canvas); | 223 PaintTitleBar(canvas); |
220 if (ShouldShowClientEdge()) | 224 if (ShouldShowClientEdge()) |
221 PaintRestoredClientEdge(canvas); | 225 PaintRestoredClientEdge(canvas); |
222 } | 226 } |
223 | 227 |
224 void CustomFrameView::Layout() { | 228 void CustomFrameView::Layout() { |
225 LayoutWindowControls(); | 229 if (ShouldShowTitleBarAndBorder()) { |
226 LayoutTitleBar(); | 230 LayoutWindowControls(); |
| 231 LayoutTitleBar(); |
| 232 } |
| 233 |
227 LayoutClientView(); | 234 LayoutClientView(); |
228 } | 235 } |
229 | 236 |
230 gfx::Size CustomFrameView::GetPreferredSize() { | 237 gfx::Size CustomFrameView::GetPreferredSize() { |
231 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 238 return frame_->non_client_view()->GetWindowBoundsForClientBounds( |
232 gfx::Rect(frame_->client_view()->GetPreferredSize())).size(); | 239 gfx::Rect(frame_->client_view()->GetPreferredSize())).size(); |
233 } | 240 } |
234 | 241 |
235 gfx::Size CustomFrameView::GetMinimumSize() { | 242 gfx::Size CustomFrameView::GetMinimumSize() { |
236 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 243 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 | 323 // 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 | 324 // 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 | 325 // 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 | 326 // 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. | 327 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. |
321 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - | 328 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - |
322 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; | 329 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; |
323 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); | 330 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); |
324 } | 331 } |
325 | 332 |
| 333 bool CustomFrameView::ShouldShowTitleBarAndBorder() const { |
| 334 if (ViewsDelegate::views_delegate) { |
| 335 return !ViewsDelegate::views_delegate->WindowManagerProvidesTitleBar( |
| 336 frame_->IsMaximized()); |
| 337 } |
| 338 |
| 339 return true; |
| 340 } |
| 341 |
326 bool CustomFrameView::ShouldShowClientEdge() const { | 342 bool CustomFrameView::ShouldShowClientEdge() const { |
327 return !frame_->IsMaximized(); | 343 return !frame_->IsMaximized() && ShouldShowTitleBarAndBorder(); |
328 } | 344 } |
329 | 345 |
330 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { | 346 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { |
331 frame_background_->set_frame_color(GetFrameColor()); | 347 frame_background_->set_frame_color(GetFrameColor()); |
332 const gfx::ImageSkia* frame_image = GetFrameImage(); | 348 const gfx::ImageSkia* frame_image = GetFrameImage(); |
333 frame_background_->set_theme_image(frame_image); | 349 frame_background_->set_theme_image(frame_image); |
334 frame_background_->set_top_area_height(frame_image->height()); | 350 frame_background_->set_top_area_height(frame_image->height()); |
335 | 351 |
336 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 352 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
337 | 353 |
(...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 | 558 // midline rather than below. This compensates for how the icon is already |
543 // biased downwards (see IconBounds()) and helps prevent descenders on the | 559 // biased downwards (see IconBounds()) and helps prevent descenders on the |
544 // title from overlapping the 3D edge at the bottom of the titlebar. | 560 // title from overlapping the 3D edge at the bottom of the titlebar. |
545 title_bounds_.SetRect(title_x, | 561 title_bounds_.SetRect(title_x, |
546 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), | 562 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), |
547 std::max(0, minimize_button_->x() - kTitleCaptionSpacing - | 563 std::max(0, minimize_button_->x() - kTitleCaptionSpacing - |
548 title_x), title_height); | 564 title_x), title_height); |
549 } | 565 } |
550 | 566 |
551 void CustomFrameView::LayoutClientView() { | 567 void CustomFrameView::LayoutClientView() { |
| 568 if (!ShouldShowTitleBarAndBorder()) { |
| 569 client_view_bounds_ = bounds(); |
| 570 return; |
| 571 } |
| 572 |
552 int top_height = NonClientTopBorderHeight(); | 573 int top_height = NonClientTopBorderHeight(); |
553 int border_thickness = NonClientBorderThickness(); | 574 int border_thickness = NonClientBorderThickness(); |
554 client_view_bounds_.SetRect(border_thickness, top_height, | 575 client_view_bounds_.SetRect(border_thickness, top_height, |
555 std::max(0, width() - (2 * border_thickness)), | 576 std::max(0, width() - (2 * border_thickness)), |
556 std::max(0, height() - top_height - border_thickness)); | 577 std::max(0, height() - top_height - border_thickness)); |
557 } | 578 } |
558 | 579 |
559 ImageButton* CustomFrameView::InitWindowCaptionButton( | 580 ImageButton* CustomFrameView::InitWindowCaptionButton( |
560 int accessibility_string_id, | 581 int accessibility_string_id, |
561 int normal_image_id, | 582 int normal_image_id, |
562 int hot_image_id, | 583 int hot_image_id, |
563 int pushed_image_id) { | 584 int pushed_image_id) { |
564 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 585 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
565 ImageButton* button = new ImageButton(this); | 586 ImageButton* button = new ImageButton(this); |
566 button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id)); | 587 button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id)); |
567 button->SetImage(CustomButton::STATE_NORMAL, | 588 button->SetImage(CustomButton::STATE_NORMAL, |
568 rb.GetImageNamed(normal_image_id).ToImageSkia()); | 589 rb.GetImageNamed(normal_image_id).ToImageSkia()); |
569 button->SetImage(CustomButton::STATE_HOVERED, | 590 button->SetImage(CustomButton::STATE_HOVERED, |
570 rb.GetImageNamed(hot_image_id).ToImageSkia()); | 591 rb.GetImageNamed(hot_image_id).ToImageSkia()); |
571 button->SetImage(CustomButton::STATE_PRESSED, | 592 button->SetImage(CustomButton::STATE_PRESSED, |
572 rb.GetImageNamed(pushed_image_id).ToImageSkia()); | 593 rb.GetImageNamed(pushed_image_id).ToImageSkia()); |
573 AddChildView(button); | 594 AddChildView(button); |
574 return button; | 595 return button; |
575 } | 596 } |
576 | 597 |
577 } // namespace views | 598 } // namespace views |
OLD | NEW |