| 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 "ash/wm/frame_painter.h" | 5 #include "ash/wm/frame_painter.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/root_window_settings.h" | 11 #include "ash/root_window_settings.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 14 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 14 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
| 15 #include "ash/wm/property_util.h" | 15 #include "ash/wm/window_state.h" |
| 16 #include "ash/wm/window_settings.h" | |
| 17 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 18 #include "base/logging.h" // DCHECK | 17 #include "base/logging.h" // DCHECK |
| 19 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
| 22 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
| 23 #include "third_party/skia/include/core/SkPath.h" | 22 #include "third_party/skia/include/core/SkPath.h" |
| 24 #include "ui/aura/client/aura_constants.h" | 23 #include "ui/aura/client/aura_constants.h" |
| 25 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
| 26 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 previous_theme_frame_overlay_id_(0), | 222 previous_theme_frame_overlay_id_(0), |
| 224 previous_opacity_(0), | 223 previous_opacity_(0), |
| 225 crossfade_theme_frame_id_(0), | 224 crossfade_theme_frame_id_(0), |
| 226 crossfade_theme_frame_overlay_id_(0), | 225 crossfade_theme_frame_overlay_id_(0), |
| 227 crossfade_opacity_(0) {} | 226 crossfade_opacity_(0) {} |
| 228 | 227 |
| 229 FramePainter::~FramePainter() { | 228 FramePainter::~FramePainter() { |
| 230 // Sometimes we are destroyed before the window closes, so ensure we clean up. | 229 // Sometimes we are destroyed before the window closes, so ensure we clean up. |
| 231 if (window_) { | 230 if (window_) { |
| 232 window_->RemoveObserver(this); | 231 window_->RemoveObserver(this); |
| 233 wm::GetWindowSettings(window_)->RemoveObserver(this); | 232 wm::GetWindowState(window_)->RemoveObserver(this); |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 | 235 |
| 237 void FramePainter::Init( | 236 void FramePainter::Init( |
| 238 views::Widget* frame, | 237 views::Widget* frame, |
| 239 views::View* window_icon, | 238 views::View* window_icon, |
| 240 FrameCaptionButtonContainerView* caption_button_container) { | 239 FrameCaptionButtonContainerView* caption_button_container) { |
| 241 DCHECK(frame); | 240 DCHECK(frame); |
| 242 // window_icon may be NULL. | 241 // window_icon may be NULL. |
| 243 DCHECK(caption_button_container); | 242 DCHECK(caption_button_container); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 267 kResizeOutsideBoundsScaleForTouch); | 266 kResizeOutsideBoundsScaleForTouch); |
| 268 // Ensure we get resize cursors for a few pixels outside our bounds. | 267 // Ensure we get resize cursors for a few pixels outside our bounds. |
| 269 window_->SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); | 268 window_->SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); |
| 270 // Ensure we get resize cursors just inside our bounds as well. | 269 // Ensure we get resize cursors just inside our bounds as well. |
| 271 window_->set_hit_test_bounds_override_inner(mouse_insets); | 270 window_->set_hit_test_bounds_override_inner(mouse_insets); |
| 272 | 271 |
| 273 // Watch for maximize/restore/fullscreen state changes. Observer removes | 272 // Watch for maximize/restore/fullscreen state changes. Observer removes |
| 274 // itself in OnWindowDestroying() below, or in the destructor if we go away | 273 // itself in OnWindowDestroying() below, or in the destructor if we go away |
| 275 // before the window. | 274 // before the window. |
| 276 window_->AddObserver(this); | 275 window_->AddObserver(this); |
| 277 wm::GetWindowSettings(window_)->AddObserver(this); | 276 wm::GetWindowState(window_)->AddObserver(this); |
| 278 | 277 |
| 279 // Solo-window header updates are handled by the workspace controller when | 278 // Solo-window header updates are handled by the workspace controller when |
| 280 // this window is added to the desktop. | 279 // this window is added to the desktop. |
| 281 } | 280 } |
| 282 | 281 |
| 283 // static | 282 // static |
| 284 void FramePainter::SetSoloWindowHeadersEnabled(bool enabled) { | 283 void FramePainter::SetSoloWindowHeadersEnabled(bool enabled) { |
| 285 solo_window_header_enabled = enabled; | 284 solo_window_header_enabled = enabled; |
| 286 } | 285 } |
| 287 | 286 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 386 } |
| 388 | 387 |
| 389 bool FramePainter::ShouldUseMinimalHeaderStyle(Themed header_themed) const { | 388 bool FramePainter::ShouldUseMinimalHeaderStyle(Themed header_themed) const { |
| 390 // Use the minimalistic header style whenever |frame_| is maximized or | 389 // Use the minimalistic header style whenever |frame_| is maximized or |
| 391 // fullscreen EXCEPT: | 390 // fullscreen EXCEPT: |
| 392 // - If the user has installed a theme with custom images for the header. | 391 // - If the user has installed a theme with custom images for the header. |
| 393 // - For windows which are not tracked by the workspace code (which are used | 392 // - For windows which are not tracked by the workspace code (which are used |
| 394 // for tab dragging). | 393 // for tab dragging). |
| 395 return (frame_->IsMaximized() || frame_->IsFullscreen()) && | 394 return (frame_->IsMaximized() || frame_->IsFullscreen()) && |
| 396 header_themed == THEMED_NO && | 395 header_themed == THEMED_NO && |
| 397 wm::GetWindowSettings(frame_->GetNativeWindow())->tracked_by_workspace(); | 396 wm::GetWindowState(frame_->GetNativeWindow())->tracked_by_workspace(); |
| 398 } | 397 } |
| 399 | 398 |
| 400 void FramePainter::PaintHeader(views::NonClientFrameView* view, | 399 void FramePainter::PaintHeader(views::NonClientFrameView* view, |
| 401 gfx::Canvas* canvas, | 400 gfx::Canvas* canvas, |
| 402 HeaderMode header_mode, | 401 HeaderMode header_mode, |
| 403 int theme_frame_id, | 402 int theme_frame_id, |
| 404 int theme_frame_overlay_id) { | 403 int theme_frame_overlay_id) { |
| 405 bool initial_paint = (previous_theme_frame_id_ == 0); | 404 bool initial_paint = (previous_theme_frame_id_ == 0); |
| 406 if (!initial_paint && | 405 if (!initial_paint && |
| 407 (previous_theme_frame_id_ != theme_frame_id || | 406 (previous_theme_frame_id_ != theme_frame_id || |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 previous_theme_frame_id_ = 0; | 611 previous_theme_frame_id_ = 0; |
| 613 previous_theme_frame_overlay_id_ = 0; | 612 previous_theme_frame_overlay_id_ = 0; |
| 614 | 613 |
| 615 if (crossfade_animation_.get() && crossfade_animation_->is_animating()) { | 614 if (crossfade_animation_.get() && crossfade_animation_->is_animating()) { |
| 616 crossfade_animation_.reset(); | 615 crossfade_animation_.reset(); |
| 617 frame_->non_client_view()->SchedulePaintInRect(header_frame_bounds_); | 616 frame_->non_client_view()->SchedulePaintInRect(header_frame_bounds_); |
| 618 } | 617 } |
| 619 } | 618 } |
| 620 | 619 |
| 621 /////////////////////////////////////////////////////////////////////////////// | 620 /////////////////////////////////////////////////////////////////////////////// |
| 622 // WindowSettings::jObserver overrides: | 621 // WindowState::Observer overrides: |
| 623 void FramePainter::OnTrackedByWorkspaceChanged(aura::Window* window, | 622 void FramePainter::OnTrackedByWorkspaceChanged(aura::Window* window, |
| 624 bool old) { | 623 bool old) { |
| 625 // When 'TrackedByWorkspace' changes, we are going to paint the header | 624 // When 'TrackedByWorkspace' changes, we are going to paint the header |
| 626 // differently. Schedule a paint to ensure everything is updated correctly. | 625 // differently. Schedule a paint to ensure everything is updated correctly. |
| 627 if (wm::GetWindowSettings(window)->tracked_by_workspace()) | 626 if (wm::GetWindowState(window)->tracked_by_workspace()) |
| 628 frame_->non_client_view()->SchedulePaint(); | 627 frame_->non_client_view()->SchedulePaint(); |
| 629 } | 628 } |
| 630 | 629 |
| 631 /////////////////////////////////////////////////////////////////////////////// | 630 /////////////////////////////////////////////////////////////////////////////// |
| 632 // aura::WindowObserver overrides: | 631 // aura::WindowObserver overrides: |
| 633 | 632 |
| 634 void FramePainter::OnWindowPropertyChanged(aura::Window* window, | 633 void FramePainter::OnWindowPropertyChanged(aura::Window* window, |
| 635 const void* key, | 634 const void* key, |
| 636 intptr_t old) { | 635 intptr_t old) { |
| 637 if (key != aura::client::kShowStateKey) | 636 if (key != aura::client::kShowStateKey) |
| 638 return; | 637 return; |
| 639 | 638 |
| 640 // Maximized and fullscreen windows don't want resize handles overlapping the | 639 // Maximized and fullscreen windows don't want resize handles overlapping the |
| 641 // content area, because when the user moves the cursor to the right screen | 640 // content area, because when the user moves the cursor to the right screen |
| 642 // edge we want them to be able to hit the scroll bar. | 641 // edge we want them to be able to hit the scroll bar. |
| 643 if (ash::wm::IsWindowMaximized(window) || | 642 wm::WindowState* window_state = wm::GetWindowState(window); |
| 644 ash::wm::IsWindowFullscreen(window)) { | 643 if (window_state->IsMaximizedOrFullscreen()) { |
| 645 window->set_hit_test_bounds_override_inner(gfx::Insets()); | 644 window->set_hit_test_bounds_override_inner(gfx::Insets()); |
| 646 } else { | 645 } else { |
| 647 window->set_hit_test_bounds_override_inner( | 646 window->set_hit_test_bounds_override_inner( |
| 648 gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize, | 647 gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize, |
| 649 kResizeInsideBoundsSize, kResizeInsideBoundsSize)); | 648 kResizeInsideBoundsSize, kResizeInsideBoundsSize)); |
| 650 } | 649 } |
| 651 } | 650 } |
| 652 | 651 |
| 653 void FramePainter::OnWindowVisibilityChanged(aura::Window* window, | 652 void FramePainter::OnWindowVisibilityChanged(aura::Window* window, |
| 654 bool visible) { | 653 bool visible) { |
| 655 // OnWindowVisibilityChanged can be called for the child windows of |window_|. | 654 // OnWindowVisibilityChanged can be called for the child windows of |window_|. |
| 656 if (window != window_) | 655 if (window != window_) |
| 657 return; | 656 return; |
| 658 | 657 |
| 659 // Window visibility change may trigger the change of window solo-ness in a | 658 // Window visibility change may trigger the change of window solo-ness in a |
| 660 // different window. | 659 // different window. |
| 661 UpdateSoloWindowInRoot(window_->GetRootWindow(), visible ? NULL : window_); | 660 UpdateSoloWindowInRoot(window_->GetRootWindow(), visible ? NULL : window_); |
| 662 } | 661 } |
| 663 | 662 |
| 664 void FramePainter::OnWindowDestroying(aura::Window* destroying) { | 663 void FramePainter::OnWindowDestroying(aura::Window* destroying) { |
| 665 DCHECK_EQ(window_, destroying); | 664 DCHECK_EQ(window_, destroying); |
| 666 | 665 |
| 667 // Must be removed here and not in the destructor, as the aura::Window is | 666 // Must be removed here and not in the destructor, as the aura::Window is |
| 668 // already destroyed when our destructor runs. | 667 // already destroyed when our destructor runs. |
| 669 window_->RemoveObserver(this); | 668 window_->RemoveObserver(this); |
| 670 wm::GetWindowSettings(window_)->RemoveObserver(this); | 669 wm::GetWindowState(window_)->RemoveObserver(this); |
| 671 | 670 |
| 672 // If we have two or more windows open and we close this one, we might trigger | 671 // If we have two or more windows open and we close this one, we might trigger |
| 673 // the solo window appearance for another window. | 672 // the solo window appearance for another window. |
| 674 UpdateSoloWindowInRoot(window_->GetRootWindow(), window_); | 673 UpdateSoloWindowInRoot(window_->GetRootWindow(), window_); |
| 675 | 674 |
| 676 window_ = NULL; | 675 window_ = NULL; |
| 677 } | 676 } |
| 678 | 677 |
| 679 void FramePainter::OnWindowBoundsChanged(aura::Window* window, | 678 void FramePainter::OnWindowBoundsChanged(aura::Window* window, |
| 680 const gfx::Rect& old_bounds, | 679 const gfx::Rect& old_bounds, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 int FramePainter::GetCaptionButtonContainerCenterY() const { | 719 int FramePainter::GetCaptionButtonContainerCenterY() const { |
| 721 return caption_button_container_->y() + | 720 return caption_button_container_->y() + |
| 722 caption_button_container_->height() / 2; | 721 caption_button_container_->height() / 2; |
| 723 } | 722 } |
| 724 | 723 |
| 725 int FramePainter::GetHeaderCornerRadius() const { | 724 int FramePainter::GetHeaderCornerRadius() const { |
| 726 // Use square corners for maximized and fullscreen windows when they are | 725 // Use square corners for maximized and fullscreen windows when they are |
| 727 // tracked by the workspace code. (Windows which are not tracked by the | 726 // tracked by the workspace code. (Windows which are not tracked by the |
| 728 // workspace code are used for tab dragging.) | 727 // workspace code are used for tab dragging.) |
| 729 bool square_corners = ((frame_->IsMaximized() || frame_->IsFullscreen())) && | 728 bool square_corners = ((frame_->IsMaximized() || frame_->IsFullscreen())) && |
| 730 wm::GetWindowSettings(frame_->GetNativeWindow())->tracked_by_workspace(); | 729 wm::GetWindowState(frame_->GetNativeWindow())->tracked_by_workspace(); |
| 731 const int kCornerRadius = 2; | 730 const int kCornerRadius = 2; |
| 732 return square_corners ? 0 : kCornerRadius; | 731 return square_corners ? 0 : kCornerRadius; |
| 733 } | 732 } |
| 734 | 733 |
| 735 int FramePainter::GetHeaderOpacity( | 734 int FramePainter::GetHeaderOpacity( |
| 736 HeaderMode header_mode, | 735 HeaderMode header_mode, |
| 737 int theme_frame_id, | 736 int theme_frame_id, |
| 738 int theme_frame_overlay_id) const { | 737 int theme_frame_overlay_id) const { |
| 739 // User-provided themes are painted fully opaque. | 738 // User-provided themes are painted fully opaque. |
| 740 ui::ThemeProvider* theme_provider = frame_->GetThemeProvider(); | 739 ui::ThemeProvider* theme_provider = frame_->GetThemeProvider(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 std::vector<Window*> windows = GetWindowsForSoloHeaderUpdate(root_window); | 776 std::vector<Window*> windows = GetWindowsForSoloHeaderUpdate(root_window); |
| 778 for (std::vector<Window*>::const_iterator it = windows.begin(); | 777 for (std::vector<Window*>::const_iterator it = windows.begin(); |
| 779 it != windows.end(); | 778 it != windows.end(); |
| 780 ++it) { | 779 ++it) { |
| 781 Window* window = *it; | 780 Window* window = *it; |
| 782 // Various sorts of windows "don't count" for this computation. | 781 // Various sorts of windows "don't count" for this computation. |
| 783 if (ignore_window == window || | 782 if (ignore_window == window || |
| 784 !IsSoloWindowHeaderCandidate(window) || | 783 !IsSoloWindowHeaderCandidate(window) || |
| 785 !IsVisibleToRoot(window)) | 784 !IsVisibleToRoot(window)) |
| 786 continue; | 785 continue; |
| 787 if (wm::IsWindowMaximized(window)) | 786 if (wm::GetWindowState(window)->IsMaximized()) |
| 788 return false; | 787 return false; |
| 789 ++visible_window_count; | 788 ++visible_window_count; |
| 790 if (visible_window_count > 1) | 789 if (visible_window_count > 1) |
| 791 return false; | 790 return false; |
| 792 } | 791 } |
| 793 // Count must be tested because all windows might be "don't count" windows | 792 // Count must be tested because all windows might be "don't count" windows |
| 794 // in the loop above. | 793 // in the loop above. |
| 795 return visible_window_count == 1; | 794 return visible_window_count == 1; |
| 796 } | 795 } |
| 797 | 796 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 // icon. Don't use |window_icon_| for this computation as it may be NULL. | 840 // icon. Don't use |window_icon_| for this computation as it may be NULL. |
| 842 int title_y = GetCaptionButtonContainerCenterY() - title_font.GetHeight() / 2; | 841 int title_y = GetCaptionButtonContainerCenterY() - title_font.GetHeight() / 2; |
| 843 return gfx::Rect( | 842 return gfx::Rect( |
| 844 title_x, | 843 title_x, |
| 845 std::max(0, title_y), | 844 std::max(0, title_y), |
| 846 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), | 845 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), |
| 847 title_font.GetHeight()); | 846 title_font.GetHeight()); |
| 848 } | 847 } |
| 849 | 848 |
| 850 } // namespace ash | 849 } // namespace ash |
| OLD | NEW |