| 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 "ash/wm/header_painter.h" | 5 #include "ash/wm/header_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/window_state.h" | 15 #include "ash/wm/window_state.h" |
| 16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 17 #include "base/logging.h" // DCHECK | 17 #include "base/logging.h" // DCHECK |
| 18 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
| 21 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
| 22 #include "third_party/skia/include/core/SkPath.h" | 22 #include "third_party/skia/include/core/SkPath.h" |
| 23 #include "ui/aura/client/aura_constants.h" | 23 #include "ui/aura/client/aura_constants.h" |
| 24 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
| 25 #include "ui/aura/root_window.h" | |
| 26 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 27 #include "ui/base/hit_test.h" | 26 #include "ui/base/hit_test.h" |
| 28 #include "ui/base/layout.h" | 27 #include "ui/base/layout.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/base/theme_provider.h" | 29 #include "ui/base/theme_provider.h" |
| 31 #include "ui/gfx/animation/slide_animation.h" | 30 #include "ui/gfx/animation/slide_animation.h" |
| 32 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/font.h" | 32 #include "ui/gfx/font.h" |
| 34 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
| 35 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return window && | 164 return window && |
| 166 window->type() == aura::client::WINDOW_TYPE_NORMAL && | 165 window->type() == aura::client::WINDOW_TYPE_NORMAL && |
| 167 window->layer() && | 166 window->layer() && |
| 168 window->layer()->type() != ui::LAYER_NOT_DRAWN && | 167 window->layer()->type() != ui::LAYER_NOT_DRAWN && |
| 169 window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE && | 168 window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE && |
| 170 !window->GetProperty(ash::kConstrainedWindowKey); | 169 !window->GetProperty(ash::kConstrainedWindowKey); |
| 171 } | 170 } |
| 172 | 171 |
| 173 // Returns a list of windows in |root_window|| that potentially could have | 172 // Returns a list of windows in |root_window|| that potentially could have |
| 174 // a transparent solo-window header. | 173 // a transparent solo-window header. |
| 175 std::vector<Window*> GetWindowsForSoloHeaderUpdate(RootWindow* root_window) { | 174 std::vector<Window*> GetWindowsForSoloHeaderUpdate(Window* root_window) { |
| 176 std::vector<Window*> windows; | 175 std::vector<Window*> windows; |
| 177 // Avoid memory allocations for typical window counts. | 176 // Avoid memory allocations for typical window counts. |
| 178 windows.reserve(16); | 177 windows.reserve(16); |
| 179 // Collect windows from the desktop. | 178 // Collect windows from the desktop. |
| 180 Window* desktop = ash::Shell::GetContainer( | 179 Window* desktop = ash::Shell::GetContainer( |
| 181 root_window, ash::internal::kShellWindowId_DefaultContainer); | 180 root_window, ash::internal::kShellWindowId_DefaultContainer); |
| 182 windows.insert(windows.end(), | 181 windows.insert(windows.end(), |
| 183 desktop->children().begin(), | 182 desktop->children().begin(), |
| 184 desktop->children().end()); | 183 desktop->children().end()); |
| 185 // Collect "always on top" windows. | 184 // Collect "always on top" windows. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Solo-window header updates are handled by the WorkspaceLayoutManager when | 266 // Solo-window header updates are handled by the WorkspaceLayoutManager when |
| 268 // this window is added to the desktop. | 267 // this window is added to the desktop. |
| 269 } | 268 } |
| 270 | 269 |
| 271 // static | 270 // static |
| 272 void HeaderPainter::SetSoloWindowHeadersEnabled(bool enabled) { | 271 void HeaderPainter::SetSoloWindowHeadersEnabled(bool enabled) { |
| 273 solo_window_header_enabled = enabled; | 272 solo_window_header_enabled = enabled; |
| 274 } | 273 } |
| 275 | 274 |
| 276 // static | 275 // static |
| 277 void HeaderPainter::UpdateSoloWindowHeader(RootWindow* root_window) { | 276 void HeaderPainter::UpdateSoloWindowHeader(Window* root_window) { |
| 278 // Use a separate function here so callers outside of HeaderPainter don't need | 277 // Use a separate function here so callers outside of HeaderPainter don't need |
| 279 // to know about "ignorable_window". | 278 // to know about "ignorable_window". |
| 280 UpdateSoloWindowInRoot(root_window, NULL /* ignorable_window */); | 279 UpdateSoloWindowInRoot(root_window, NULL /* ignorable_window */); |
| 281 } | 280 } |
| 282 | 281 |
| 283 // static | 282 // static |
| 284 gfx::Rect HeaderPainter::GetBoundsForClientView( | 283 gfx::Rect HeaderPainter::GetBoundsForClientView( |
| 285 int header_height, | 284 int header_height, |
| 286 const gfx::Rect& window_bounds) { | 285 const gfx::Rect& window_bounds) { |
| 287 gfx::Rect client_bounds(window_bounds); | 286 gfx::Rect client_bounds(window_bounds); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 return kActiveWindowOpacity; | 682 return kActiveWindowOpacity; |
| 684 return kInactiveWindowOpacity; | 683 return kInactiveWindowOpacity; |
| 685 } | 684 } |
| 686 | 685 |
| 687 bool HeaderPainter::UseSoloWindowHeader() const { | 686 bool HeaderPainter::UseSoloWindowHeader() const { |
| 688 if (!solo_window_header_enabled) | 687 if (!solo_window_header_enabled) |
| 689 return false; | 688 return false; |
| 690 // Don't use transparent headers for panels, pop-ups, etc. | 689 // Don't use transparent headers for panels, pop-ups, etc. |
| 691 if (!IsSoloWindowHeaderCandidate(window_)) | 690 if (!IsSoloWindowHeaderCandidate(window_)) |
| 692 return false; | 691 return false; |
| 693 aura::RootWindow* root = window_->GetRootWindow(); | 692 aura::Window* root = window_->GetRootWindow(); |
| 694 // Don't recompute every time, as it would require many window property | 693 // Don't recompute every time, as it would require many window property |
| 695 // lookups. | 694 // lookups. |
| 696 return internal::GetRootWindowSettings(root)->solo_window_header; | 695 return internal::GetRootWindowSettings(root)->solo_window_header; |
| 697 } | 696 } |
| 698 | 697 |
| 699 // static | 698 // static |
| 700 bool HeaderPainter::UseSoloWindowHeaderInRoot(RootWindow* root_window, | 699 bool HeaderPainter::UseSoloWindowHeaderInRoot(Window* root_window, |
| 701 Window* ignore_window) { | 700 Window* ignore_window) { |
| 702 int visible_window_count = 0; | 701 int visible_window_count = 0; |
| 703 std::vector<Window*> windows = GetWindowsForSoloHeaderUpdate(root_window); | 702 std::vector<Window*> windows = GetWindowsForSoloHeaderUpdate(root_window); |
| 704 for (std::vector<Window*>::const_iterator it = windows.begin(); | 703 for (std::vector<Window*>::const_iterator it = windows.begin(); |
| 705 it != windows.end(); | 704 it != windows.end(); |
| 706 ++it) { | 705 ++it) { |
| 707 Window* window = *it; | 706 Window* window = *it; |
| 708 // Various sorts of windows "don't count" for this computation. | 707 // Various sorts of windows "don't count" for this computation. |
| 709 if (ignore_window == window || | 708 if (ignore_window == window || |
| 710 !IsSoloWindowHeaderCandidate(window) || | 709 !IsSoloWindowHeaderCandidate(window) || |
| 711 !IsVisibleToRoot(window)) | 710 !IsVisibleToRoot(window)) |
| 712 continue; | 711 continue; |
| 713 if (wm::GetWindowState(window)->IsMaximized()) | 712 if (wm::GetWindowState(window)->IsMaximized()) |
| 714 return false; | 713 return false; |
| 715 ++visible_window_count; | 714 ++visible_window_count; |
| 716 if (visible_window_count > 1) | 715 if (visible_window_count > 1) |
| 717 return false; | 716 return false; |
| 718 } | 717 } |
| 719 // Count must be tested because all windows might be "don't count" windows | 718 // Count must be tested because all windows might be "don't count" windows |
| 720 // in the loop above. | 719 // in the loop above. |
| 721 return visible_window_count == 1; | 720 return visible_window_count == 1; |
| 722 } | 721 } |
| 723 | 722 |
| 724 // static | 723 // static |
| 725 void HeaderPainter::UpdateSoloWindowInRoot(RootWindow* root, | 724 void HeaderPainter::UpdateSoloWindowInRoot(Window* root, |
| 726 Window* ignore_window) { | 725 Window* ignore_window) { |
| 727 #if defined(OS_WIN) | 726 #if defined(OS_WIN) |
| 728 // Non-Ash Windows doesn't do solo-window counting for transparency effects, | 727 // Non-Ash Windows doesn't do solo-window counting for transparency effects, |
| 729 // as the desktop background and window frames are managed by the OS. | 728 // as the desktop background and window frames are managed by the OS. |
| 730 if (!ash::Shell::HasInstance()) | 729 if (!ash::Shell::HasInstance()) |
| 731 return; | 730 return; |
| 732 #endif | 731 #endif |
| 733 if (!root) | 732 if (!root) |
| 734 return; | 733 return; |
| 735 internal::RootWindowSettings* root_window_settings = | 734 internal::RootWindowSettings* root_window_settings = |
| 736 internal::GetRootWindowSettings(root); | 735 internal::GetRootWindowSettings(root); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 767 // icon. Don't use |window_icon_| for this computation as it may be NULL. | 766 // icon. Don't use |window_icon_| for this computation as it may be NULL. |
| 768 int title_y = GetCaptionButtonContainerCenterY() - title_font.GetHeight() / 2; | 767 int title_y = GetCaptionButtonContainerCenterY() - title_font.GetHeight() / 2; |
| 769 return gfx::Rect( | 768 return gfx::Rect( |
| 770 title_x, | 769 title_x, |
| 771 std::max(0, title_y), | 770 std::max(0, title_y), |
| 772 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), | 771 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), |
| 773 title_font.GetHeight()); | 772 title_font.GetHeight()); |
| 774 } | 773 } |
| 775 | 774 |
| 776 } // namespace ash | 775 } // namespace ash |
| OLD | NEW |