Chromium Code Reviews| 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/overview/scoped_transform_overview_window.h" | 5 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/wm/overview/scoped_overview_animation_settings.h" | 11 #include "ash/wm/overview/scoped_overview_animation_settings.h" |
| 12 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" | 12 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" |
| 13 #include "ash/wm/overview/window_selector_item.h" | 13 #include "ash/wm/overview/window_selector_item.h" |
| 14 #include "ash/wm/window_mirror_view.h" | 14 #include "ash/wm/window_mirror_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.h" | 17 #include "ash/wm_window.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/window.h" | |
| 22 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/geometry/safe_integer_conversions.h" | 26 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 25 #include "ui/gfx/transform_util.h" | 27 #include "ui/gfx/transform_util.h" |
| 26 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 27 | 29 #include "ui/wm/core/coordinate_conversion.h" |
| 28 using WmWindows = std::vector<ash::WmWindow*>; | 30 #include "ui/wm/core/window_util.h" |
| 29 | 31 |
| 30 namespace ash { | 32 namespace ash { |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // When set to true by tests makes closing the widget synchronous. | 36 // When set to true by tests makes closing the widget synchronous. |
| 35 bool immediate_close_for_tests = false; | 37 bool immediate_close_for_tests = false; |
| 36 | 38 |
| 37 // Delay closing window to allow it to shrink and fade out. | 39 // Delay closing window to allow it to shrink and fade out. |
| 38 const int kCloseWindowDelayInMilliseconds = 150; | 40 const int kCloseWindowDelayInMilliseconds = 150; |
| 39 | 41 |
| 40 WmWindow* GetTransientRoot(WmWindow* window) { | 42 aura::Window* GetTransientRoot(aura::Window* window) { |
| 41 while (window && window->GetTransientParent()) | 43 while (window && ::wm::GetTransientParent(window)) |
| 42 window = window->GetTransientParent(); | 44 window = ::wm::GetTransientParent(window); |
| 43 return window; | 45 return window; |
| 44 } | 46 } |
| 45 | 47 |
| 46 std::unique_ptr<ScopedOverviewAnimationSettings> | 48 std::unique_ptr<ScopedOverviewAnimationSettings> |
| 47 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type, | 49 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type, |
| 48 WmWindow* window) { | 50 aura::Window* window) { |
| 49 return ScopedOverviewAnimationSettingsFactory::Get() | 51 return ScopedOverviewAnimationSettingsFactory::Get() |
| 50 ->CreateOverviewAnimationSettings(animation_type, window); | 52 ->CreateOverviewAnimationSettings(animation_type, window); |
| 51 } | 53 } |
| 52 | 54 |
| 53 // An iterator class that traverses a WmWindow and all of its transient | 55 // An iterator class that traverses an aura::Window and all of its transient |
| 54 // descendants. | 56 // descendants. |
| 55 class TransientDescendantIterator { | 57 class TransientDescendantIterator { |
| 56 public: | 58 public: |
| 57 // Creates an empty iterator. | 59 // Creates an empty iterator. |
| 58 TransientDescendantIterator(); | 60 TransientDescendantIterator(); |
| 59 | 61 |
| 60 // Copy constructor required for iterator purposes. | 62 // Copy constructor required for iterator purposes. |
| 61 TransientDescendantIterator(const TransientDescendantIterator& other) = | 63 TransientDescendantIterator(const TransientDescendantIterator& other) = |
| 62 default; | 64 default; |
| 63 | 65 |
| 64 // Iterates over |root_window| and all of its transient descendants. | 66 // Iterates over |root_window| and all of its transient descendants. |
| 65 // Note |root_window| must not have a transient parent. | 67 // Note |root_window| must not have a transient parent. |
| 66 explicit TransientDescendantIterator(WmWindow* root_window); | 68 explicit TransientDescendantIterator(aura::Window* root_window); |
| 67 | 69 |
| 68 // Prefix increment operator. This assumes there are more items (i.e. | 70 // Prefix increment operator. This assumes there are more items (i.e. |
| 69 // *this != TransientDescendantIterator()). | 71 // *this != TransientDescendantIterator()). |
| 70 const TransientDescendantIterator& operator++(); | 72 const TransientDescendantIterator& operator++(); |
| 71 | 73 |
| 72 // Comparison for STL-based loops. | 74 // Comparison for STL-based loops. |
| 73 bool operator!=(const TransientDescendantIterator& other) const; | 75 bool operator!=(const TransientDescendantIterator& other) const; |
| 74 | 76 |
| 75 // Dereference operator for STL-compatible iterators. | 77 // Dereference operator for STL-compatible iterators. |
| 76 WmWindow* operator*() const; | 78 aura::Window* operator*() const; |
| 77 | 79 |
| 78 private: | 80 private: |
| 79 // Explicit assignment operator defined because an explicit copy constructor | 81 // Explicit assignment operator defined because an explicit copy constructor |
| 80 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. | 82 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. |
| 81 TransientDescendantIterator& operator=( | 83 TransientDescendantIterator& operator=( |
| 82 const TransientDescendantIterator& other) = default; | 84 const TransientDescendantIterator& other) = default; |
| 83 | 85 |
| 84 // The current window that |this| refers to. A null |current_window_| denotes | 86 // The current window that |this| refers to. A null |current_window_| denotes |
| 85 // an empty iterator and is used as the last possible value in the traversal. | 87 // an empty iterator and is used as the last possible value in the traversal. |
| 86 WmWindow* current_window_; | 88 aura::Window* current_window_; |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 // Provides a virtual container implementing begin() and end() for a sequence of | 91 // Provides a virtual container implementing begin() and end() for a sequence of |
| 90 // TransientDescendantIterators. This can be used in range-based for loops. | 92 // TransientDescendantIterators. This can be used in range-based for loops. |
| 91 class TransientDescendantIteratorRange { | 93 class TransientDescendantIteratorRange { |
| 92 public: | 94 public: |
| 93 explicit TransientDescendantIteratorRange( | 95 explicit TransientDescendantIteratorRange( |
| 94 const TransientDescendantIterator& begin); | 96 const TransientDescendantIterator& begin); |
| 95 | 97 |
| 96 // Copy constructor required for iterator purposes. | 98 // Copy constructor required for iterator purposes. |
| 97 TransientDescendantIteratorRange( | 99 TransientDescendantIteratorRange( |
| 98 const TransientDescendantIteratorRange& other) = default; | 100 const TransientDescendantIteratorRange& other) = default; |
| 99 | 101 |
| 100 const TransientDescendantIterator& begin() const { return begin_; } | 102 const TransientDescendantIterator& begin() const { return begin_; } |
| 101 const TransientDescendantIterator& end() const { return end_; } | 103 const TransientDescendantIterator& end() const { return end_; } |
| 102 | 104 |
| 103 private: | 105 private: |
| 104 // Explicit assignment operator defined because an explicit copy constructor | 106 // Explicit assignment operator defined because an explicit copy constructor |
| 105 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. | 107 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. |
| 106 TransientDescendantIteratorRange& operator=( | 108 TransientDescendantIteratorRange& operator=( |
| 107 const TransientDescendantIteratorRange& other) = default; | 109 const TransientDescendantIteratorRange& other) = default; |
| 108 | 110 |
| 109 TransientDescendantIterator begin_; | 111 TransientDescendantIterator begin_; |
| 110 TransientDescendantIterator end_; | 112 TransientDescendantIterator end_; |
| 111 }; | 113 }; |
| 112 | 114 |
| 113 TransientDescendantIterator::TransientDescendantIterator() | 115 TransientDescendantIterator::TransientDescendantIterator() |
| 114 : current_window_(nullptr) {} | 116 : current_window_(nullptr) {} |
| 115 | 117 |
| 116 TransientDescendantIterator::TransientDescendantIterator(WmWindow* root_window) | 118 TransientDescendantIterator::TransientDescendantIterator( |
| 119 aura::Window* root_window) | |
| 117 : current_window_(root_window) { | 120 : current_window_(root_window) { |
| 118 DCHECK(!root_window->GetTransientParent()); | 121 DCHECK(!::wm::GetTransientParent(root_window)); |
| 119 } | 122 } |
| 120 | 123 |
| 121 // Performs a pre-order traversal of the transient descendants. | 124 // Performs a pre-order traversal of the transient descendants. |
| 122 const TransientDescendantIterator& TransientDescendantIterator::operator++() { | 125 const TransientDescendantIterator& TransientDescendantIterator::operator++() { |
| 123 DCHECK(current_window_); | 126 DCHECK(current_window_); |
| 124 | 127 |
| 125 const WmWindows transient_children = current_window_->GetTransientChildren(); | 128 const aura::Window::Windows transient_children = |
| 129 ::wm::GetTransientChildren(current_window_); | |
| 126 | 130 |
| 127 if (!transient_children.empty()) { | 131 if (!transient_children.empty()) { |
| 128 current_window_ = transient_children.front(); | 132 current_window_ = transient_children.front(); |
| 129 } else { | 133 } else { |
| 130 while (current_window_) { | 134 while (current_window_) { |
| 131 WmWindow* parent = current_window_->GetTransientParent(); | 135 aura::Window* parent = ::wm::GetTransientParent(current_window_); |
| 132 if (!parent) { | 136 if (!parent) { |
| 133 current_window_ = nullptr; | 137 current_window_ = nullptr; |
| 134 break; | 138 break; |
| 135 } | 139 } |
| 136 const WmWindows transient_siblings = parent->GetTransientChildren(); | 140 const aura::Window::Windows transient_siblings = |
| 141 ::wm::GetTransientChildren(parent); | |
| 137 auto iter = std::find(transient_siblings.begin(), | 142 auto iter = std::find(transient_siblings.begin(), |
| 138 transient_siblings.end(), current_window_); | 143 transient_siblings.end(), current_window_); |
| 139 ++iter; | 144 ++iter; |
| 140 if (iter != transient_siblings.end()) { | 145 if (iter != transient_siblings.end()) { |
| 141 current_window_ = *iter; | 146 current_window_ = *iter; |
| 142 break; | 147 break; |
| 143 } | 148 } |
| 144 current_window_ = current_window_->GetTransientParent(); | 149 current_window_ = ::wm::GetTransientParent(current_window_); |
| 145 } | 150 } |
| 146 } | 151 } |
| 147 return *this; | 152 return *this; |
| 148 } | 153 } |
| 149 | 154 |
| 150 bool TransientDescendantIterator::operator!=( | 155 bool TransientDescendantIterator::operator!=( |
| 151 const TransientDescendantIterator& other) const { | 156 const TransientDescendantIterator& other) const { |
| 152 return current_window_ != other.current_window_; | 157 return current_window_ != other.current_window_; |
| 153 } | 158 } |
| 154 | 159 |
| 155 WmWindow* TransientDescendantIterator::operator*() const { | 160 aura::Window* TransientDescendantIterator::operator*() const { |
| 156 return current_window_; | 161 return current_window_; |
| 157 } | 162 } |
| 158 | 163 |
| 159 TransientDescendantIteratorRange::TransientDescendantIteratorRange( | 164 TransientDescendantIteratorRange::TransientDescendantIteratorRange( |
| 160 const TransientDescendantIterator& begin) | 165 const TransientDescendantIterator& begin) |
| 161 : begin_(begin) {} | 166 : begin_(begin) {} |
| 162 | 167 |
| 163 TransientDescendantIteratorRange GetTransientTreeIterator(WmWindow* window) { | 168 TransientDescendantIteratorRange GetTransientTreeIterator( |
| 169 aura::Window* window) { | |
| 164 return TransientDescendantIteratorRange( | 170 return TransientDescendantIteratorRange( |
| 165 TransientDescendantIterator(GetTransientRoot(window))); | 171 TransientDescendantIterator(GetTransientRoot(window))); |
| 166 } | 172 } |
| 167 | 173 |
| 168 } // namespace | 174 } // namespace |
| 169 | 175 |
| 170 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window) | 176 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow( |
| 177 aura::Window* window) | |
| 171 : window_(window), | 178 : window_(window), |
| 172 determined_original_window_shape_(false), | 179 determined_original_window_shape_(false), |
| 173 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), | 180 ignored_by_shelf_(wm::GetWindowState(window)->ignored_by_shelf()), |
| 174 overview_started_(false), | 181 overview_started_(false), |
| 175 original_transform_(window->GetTargetTransform()), | 182 original_transform_(window->layer()->GetTargetTransform()), |
| 176 original_opacity_(window->GetTargetOpacity()), | 183 original_opacity_(window->layer()->GetTargetOpacity()), |
| 177 weak_ptr_factory_(this) {} | 184 weak_ptr_factory_(this) {} |
| 178 | 185 |
| 179 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} | 186 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} |
| 180 | 187 |
| 181 void ScopedTransformOverviewWindow::RestoreWindow() { | 188 void ScopedTransformOverviewWindow::RestoreWindow() { |
| 182 ShowHeader(); | 189 ShowHeader(); |
| 183 if (minimized_widget_) { | 190 if (minimized_widget_) { |
| 184 // TODO(oshima): Use unminimize animation instead of hiding animation. | 191 // TODO(oshima): Use unminimize animation instead of hiding animation. |
| 185 minimized_widget_->CloseNow(); | 192 minimized_widget_->CloseNow(); |
| 186 minimized_widget_.reset(); | 193 minimized_widget_.reset(); |
| 187 return; | 194 return; |
| 188 } | 195 } |
| 189 ScopedAnimationSettings animation_settings_list; | 196 ScopedAnimationSettings animation_settings_list; |
| 190 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, | 197 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, |
| 191 &animation_settings_list); | 198 &animation_settings_list); |
| 192 SetTransform(window()->GetRootWindow(), original_transform_); | 199 SetTransform(window()->GetRootWindow(), original_transform_); |
| 193 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 200 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 194 CreateScopedOverviewAnimationSettings( | 201 CreateScopedOverviewAnimationSettings( |
| 195 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, | 202 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, |
| 196 window_); | 203 window_); |
| 197 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_); | 204 wm::GetWindowState(window_)->set_ignored_by_shelf(ignored_by_shelf_); |
| 198 SetOpacity(original_opacity_); | 205 SetOpacity(original_opacity_); |
| 199 } | 206 } |
| 200 | 207 |
| 201 void ScopedTransformOverviewWindow::BeginScopedAnimation( | 208 void ScopedTransformOverviewWindow::BeginScopedAnimation( |
| 202 OverviewAnimationType animation_type, | 209 OverviewAnimationType animation_type, |
| 203 ScopedAnimationSettings* animation_settings) { | 210 ScopedAnimationSettings* animation_settings) { |
| 204 for (auto* window : GetTransientTreeIterator(GetOverviewWindow())) { | 211 for (auto* window : GetTransientTreeIterator(GetOverviewWindow())) { |
| 205 animation_settings->push_back( | 212 animation_settings->push_back( |
| 206 CreateScopedOverviewAnimationSettings(animation_type, window)); | 213 CreateScopedOverviewAnimationSettings(animation_type, window)); |
| 207 } | 214 } |
| 208 } | 215 } |
| 209 | 216 |
| 210 bool ScopedTransformOverviewWindow::Contains(const WmWindow* target) const { | 217 bool ScopedTransformOverviewWindow::Contains(const aura::Window* target) const { |
| 211 for (auto* window : GetTransientTreeIterator(window_)) { | 218 for (auto* window : GetTransientTreeIterator(window_)) { |
| 212 if (window->Contains(target)) | 219 if (window->Contains(target)) |
| 213 return true; | 220 return true; |
| 214 } | 221 } |
| 215 WmWindow* mirror = GetOverviewWindowForMinimizedState(); | 222 aura::Window* mirror = GetOverviewWindowForMinimizedState(); |
| 216 return mirror && mirror->Contains(target); | 223 return mirror && mirror->Contains(target); |
| 217 } | 224 } |
| 218 | 225 |
| 219 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { | 226 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { |
| 220 gfx::Rect bounds; | 227 gfx::Rect bounds; |
| 221 WmWindow* overview_window = GetOverviewWindow(); | 228 aura::Window* overview_window = GetOverviewWindow(); |
| 222 for (auto* window : GetTransientTreeIterator(overview_window)) { | 229 for (auto* window : GetTransientTreeIterator(overview_window)) { |
| 223 // Ignore other window types when computing bounding box of window | 230 // Ignore other window types when computing bounding box of window |
| 224 // selector target item. | 231 // selector target item. |
| 225 if (window != overview_window && | 232 if (window != overview_window && |
| 226 window->GetType() != ui::wm::WINDOW_TYPE_NORMAL && | 233 window->type() != ui::wm::WINDOW_TYPE_NORMAL && |
| 227 window->GetType() != ui::wm::WINDOW_TYPE_PANEL) { | 234 window->type() != ui::wm::WINDOW_TYPE_PANEL) { |
| 228 continue; | 235 continue; |
| 229 } | 236 } |
| 230 bounds.Union( | 237 gfx::Rect target_bounds = window->GetTargetBounds(); |
| 231 window->GetParent()->ConvertRectToScreen(window->GetTargetBounds())); | 238 ::wm::ConvertRectToScreen(window->parent(), &target_bounds); |
| 239 bounds.Union(target_bounds); | |
| 232 } | 240 } |
| 233 return bounds; | 241 return bounds; |
| 234 } | 242 } |
| 235 | 243 |
| 236 gfx::Rect ScopedTransformOverviewWindow::GetTransformedBounds() const { | 244 gfx::Rect ScopedTransformOverviewWindow::GetTransformedBounds() const { |
| 237 const int top_inset = GetTopInset(); | 245 const int top_inset = GetTopInset(); |
| 238 gfx::Rect bounds; | 246 gfx::Rect bounds; |
| 239 WmWindow* overview_window = GetOverviewWindow(); | 247 aura::Window* overview_window = GetOverviewWindow(); |
| 240 for (auto* window : GetTransientTreeIterator(overview_window)) { | 248 for (auto* window : GetTransientTreeIterator(overview_window)) { |
| 241 // Ignore other window types when computing bounding box of window | 249 // Ignore other window types when computing bounding box of window |
| 242 // selector target item. | 250 // selector target item. |
| 243 if (window != overview_window && | 251 if (window != overview_window && |
| 244 (window->GetType() != ui::wm::WINDOW_TYPE_NORMAL && | 252 (window->type() != ui::wm::WINDOW_TYPE_NORMAL && |
| 245 window->GetType() != ui::wm::WINDOW_TYPE_PANEL)) { | 253 window->type() != ui::wm::WINDOW_TYPE_PANEL)) { |
| 246 continue; | 254 continue; |
| 247 } | 255 } |
| 248 gfx::RectF window_bounds(window->GetTargetBounds()); | 256 gfx::RectF window_bounds(window->GetTargetBounds()); |
| 249 gfx::Transform new_transform = | 257 gfx::Transform new_transform = |
| 250 TransformAboutPivot(gfx::Point(window_bounds.x(), window_bounds.y()), | 258 TransformAboutPivot(gfx::Point(window_bounds.x(), window_bounds.y()), |
| 251 window->GetTargetTransform()); | 259 window->layer()->GetTargetTransform()); |
| 252 new_transform.TransformRect(&window_bounds); | 260 new_transform.TransformRect(&window_bounds); |
| 253 | 261 |
| 254 // The preview title is shown above the preview window. Hide the window | 262 // The preview title is shown above the preview window. Hide the window |
| 255 // header for apps or browser windows with no tabs (web apps) to avoid | 263 // header for apps or browser windows with no tabs (web apps) to avoid |
| 256 // showing both the window header and the preview title. | 264 // showing both the window header and the preview title. |
| 257 if (top_inset > 0) { | 265 if (top_inset > 0) { |
| 258 gfx::RectF header_bounds(window_bounds); | 266 gfx::RectF header_bounds(window_bounds); |
| 259 header_bounds.set_height(top_inset); | 267 header_bounds.set_height(top_inset); |
| 260 new_transform.TransformRect(&header_bounds); | 268 new_transform.TransformRect(&header_bounds); |
| 261 window_bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); | 269 window_bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); |
| 262 } | 270 } |
| 263 bounds.Union(window->GetParent()->ConvertRectToScreen( | 271 gfx::Rect enclosing_bounds = ToEnclosingRect(window_bounds); |
| 264 ToEnclosingRect(window_bounds))); | 272 ::wm::ConvertRectToScreen(window->parent(), &enclosing_bounds); |
| 273 bounds.Union(enclosing_bounds); | |
| 265 } | 274 } |
| 266 return bounds; | 275 return bounds; |
| 267 } | 276 } |
| 268 | 277 |
| 269 SkColor ScopedTransformOverviewWindow::GetTopColor() const { | 278 SkColor ScopedTransformOverviewWindow::GetTopColor() const { |
| 270 for (auto* window : GetTransientTreeIterator(window_)) { | 279 for (auto* window : GetTransientTreeIterator(window_)) { |
| 271 // If there are regular windows in the transient ancestor tree, all those | 280 // If there are regular windows in the transient ancestor tree, all those |
| 272 // windows are shown in the same overview item and the header is not masked. | 281 // windows are shown in the same overview item and the header is not masked. |
| 273 if (window != window_ && (window->GetType() == ui::wm::WINDOW_TYPE_NORMAL || | 282 if (window != window_ && (window->type() == ui::wm::WINDOW_TYPE_NORMAL || |
| 274 window->GetType() == ui::wm::WINDOW_TYPE_PANEL)) { | 283 window->type() == ui::wm::WINDOW_TYPE_PANEL)) { |
| 275 return SK_ColorTRANSPARENT; | 284 return SK_ColorTRANSPARENT; |
| 276 } | 285 } |
| 277 } | 286 } |
| 278 return window_->aura_window()->GetProperty(aura::client::kTopViewColor); | 287 return window_->GetProperty(aura::client::kTopViewColor); |
| 279 } | 288 } |
| 280 | 289 |
| 281 int ScopedTransformOverviewWindow::GetTopInset() const { | 290 int ScopedTransformOverviewWindow::GetTopInset() const { |
| 282 // Mirror window doesn't have insets. | 291 // Mirror window doesn't have insets. |
| 283 if (minimized_widget_) | 292 if (minimized_widget_) |
| 284 return 0; | 293 return 0; |
| 285 for (auto* window : GetTransientTreeIterator(window_)) { | 294 for (auto* window : GetTransientTreeIterator(window_)) { |
| 286 // If there are regular windows in the transient ancestor tree, all those | 295 // If there are regular windows in the transient ancestor tree, all those |
| 287 // windows are shown in the same overview item and the header is not masked. | 296 // windows are shown in the same overview item and the header is not masked. |
| 288 if (window != window_ && (window->GetType() == ui::wm::WINDOW_TYPE_NORMAL || | 297 if (window != window_ && (window->type() == ui::wm::WINDOW_TYPE_NORMAL || |
| 289 window->GetType() == ui::wm::WINDOW_TYPE_PANEL)) { | 298 window->type() == ui::wm::WINDOW_TYPE_PANEL)) { |
| 290 return 0; | 299 return 0; |
| 291 } | 300 } |
| 292 } | 301 } |
| 293 return window_->aura_window()->GetProperty(aura::client::kTopViewInset); | 302 return window_->GetProperty(aura::client::kTopViewInset); |
| 294 } | 303 } |
| 295 | 304 |
| 296 void ScopedTransformOverviewWindow::OnWindowDestroyed() { | 305 void ScopedTransformOverviewWindow::OnWindowDestroyed() { |
| 297 window_ = nullptr; | 306 window_ = nullptr; |
| 298 } | 307 } |
| 299 | 308 |
| 300 float ScopedTransformOverviewWindow::GetItemScale(const gfx::Size& source, | 309 float ScopedTransformOverviewWindow::GetItemScale(const gfx::Size& source, |
| 301 const gfx::Size& target, | 310 const gfx::Size& target, |
| 302 int top_view_inset, | 311 int top_view_inset, |
| 303 int title_height) { | 312 int title_height) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 330 const gfx::Rect& dst_rect) { | 339 const gfx::Rect& dst_rect) { |
| 331 DCHECK(!src_rect.IsEmpty()); | 340 DCHECK(!src_rect.IsEmpty()); |
| 332 gfx::Transform transform; | 341 gfx::Transform transform; |
| 333 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); | 342 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); |
| 334 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), | 343 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), |
| 335 static_cast<float>(dst_rect.height()) / src_rect.height()); | 344 static_cast<float>(dst_rect.height()) / src_rect.height()); |
| 336 return transform; | 345 return transform; |
| 337 } | 346 } |
| 338 | 347 |
| 339 void ScopedTransformOverviewWindow::SetTransform( | 348 void ScopedTransformOverviewWindow::SetTransform( |
| 340 WmWindow* root_window, | 349 aura::Window* root_window, |
| 341 const gfx::Transform& transform) { | 350 const gfx::Transform& transform) { |
| 342 DCHECK(overview_started_); | 351 DCHECK(overview_started_); |
| 343 | 352 |
| 344 if (&transform != &original_transform_ && | 353 if (&transform != &original_transform_ && |
| 345 !determined_original_window_shape_) { | 354 !determined_original_window_shape_) { |
| 346 determined_original_window_shape_ = true; | 355 determined_original_window_shape_ = true; |
| 347 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); | 356 SkRegion* window_shape = window()->layer()->alpha_shape(); |
| 348 if (!original_window_shape_ && window_shape) | 357 if (!original_window_shape_ && window_shape) |
| 349 original_window_shape_.reset(new SkRegion(*window_shape)); | 358 original_window_shape_.reset(new SkRegion(*window_shape)); |
| 350 } | 359 } |
| 351 | 360 |
| 352 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); | 361 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); |
| 353 for (auto* window : GetTransientTreeIterator(GetOverviewWindow())) { | 362 for (auto* window : GetTransientTreeIterator(GetOverviewWindow())) { |
| 354 WmWindow* parent_window = window->GetParent(); | 363 aura::Window* parent_window = window->parent(); |
| 355 gfx::Point original_origin = | 364 gfx::Rect original_bounds(window->GetTargetBounds()); |
| 356 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); | 365 ::wm::ConvertRectToScreen(parent_window, &original_bounds); |
| 357 gfx::Transform new_transform = | 366 gfx::Transform new_transform = |
| 358 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), | 367 TransformAboutPivot(gfx::Point(target_origin.x() - original_bounds.x(), |
| 359 target_origin.y() - original_origin.y()), | 368 target_origin.y() - original_bounds.y()), |
| 360 transform); | 369 transform); |
| 361 window->SetTransform(new_transform); | 370 window->SetTransform(new_transform); |
| 362 } | 371 } |
| 363 } | 372 } |
| 364 | 373 |
| 365 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { | 374 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { |
| 366 for (auto* window : GetTransientTreeIterator(GetOverviewWindow())) { | 375 for (auto* window : GetTransientTreeIterator(GetOverviewWindow())) { |
|
msw
2017/05/23 22:50:24
optional nit: curlies not needed
varkha
2017/05/24 15:29:15
Done.
| |
| 367 window->SetOpacity(opacity); | 376 window->layer()->SetOpacity(opacity); |
| 368 } | 377 } |
| 369 } | 378 } |
| 370 | 379 |
| 371 void ScopedTransformOverviewWindow::HideHeader() { | 380 void ScopedTransformOverviewWindow::HideHeader() { |
| 372 // Mirrored Window does not have a header. | 381 // Mirrored Window does not have a header. |
| 373 if (minimized_widget_) | 382 if (minimized_widget_) |
| 374 return; | 383 return; |
| 375 gfx::Rect bounds(GetTargetBoundsInScreen().size()); | 384 gfx::Rect bounds(GetTargetBoundsInScreen().size()); |
| 376 const int inset = GetTopInset(); | 385 const int inset = GetTopInset(); |
| 377 if (inset > 0) { | 386 if (inset > 0) { |
| 378 // Use alpha shape to hide the window header. | 387 // Use alpha shape to hide the window header. |
| 379 bounds.Inset(0, inset, 0, 0); | 388 bounds.Inset(0, inset, 0, 0); |
| 380 std::unique_ptr<SkRegion> region(new SkRegion); | 389 std::unique_ptr<SkRegion> region(new SkRegion); |
| 381 region->setRect(RectToSkIRect(bounds)); | 390 region->setRect(RectToSkIRect(bounds)); |
| 382 if (original_window_shape_) | 391 if (original_window_shape_) |
| 383 region->op(*original_window_shape_, SkRegion::kIntersect_Op); | 392 region->op(*original_window_shape_, SkRegion::kIntersect_Op); |
| 384 WmWindow* window = GetOverviewWindow(); | 393 aura::Window* window = GetOverviewWindow(); |
| 385 window->GetLayer()->SetAlphaShape(std::move(region)); | 394 window->layer()->SetAlphaShape(std::move(region)); |
| 386 window->SetMasksToBounds(true); | 395 window->layer()->SetMasksToBounds(true); |
| 387 } | 396 } |
| 388 } | 397 } |
| 389 | 398 |
| 390 void ScopedTransformOverviewWindow::ShowHeader() { | 399 void ScopedTransformOverviewWindow::ShowHeader() { |
| 391 ui::Layer* layer = window()->GetLayer(); | 400 ui::Layer* layer = window()->layer(); |
| 392 if (original_window_shape_) { | 401 if (original_window_shape_) { |
| 393 layer->SetAlphaShape( | 402 layer->SetAlphaShape( |
| 394 base::MakeUnique<SkRegion>(*original_window_shape_.get())); | 403 base::MakeUnique<SkRegion>(*original_window_shape_.get())); |
| 395 } else { | 404 } else { |
| 396 layer->SetAlphaShape(nullptr); | 405 layer->SetAlphaShape(nullptr); |
| 397 } | 406 } |
| 398 window()->SetMasksToBounds(false); | 407 layer->SetMasksToBounds(false); |
| 399 } | 408 } |
| 400 | 409 |
| 401 void ScopedTransformOverviewWindow::UpdateMirrorWindowForMinimizedState() { | 410 void ScopedTransformOverviewWindow::UpdateMirrorWindowForMinimizedState() { |
| 402 // TODO(oshima): Disable animation. | 411 // TODO(oshima): Disable animation. |
| 403 if (window_->GetShowState() == ui::SHOW_STATE_MINIMIZED) { | 412 if (window_->GetProperty(aura::client::kShowStateKey) == |
| 413 ui::SHOW_STATE_MINIMIZED) { | |
| 404 if (!minimized_widget_) | 414 if (!minimized_widget_) |
| 405 CreateMirrorWindowForMinimizedState(); | 415 CreateMirrorWindowForMinimizedState(); |
| 406 } else { | 416 } else { |
| 407 minimized_widget_->CloseNow(); | 417 minimized_widget_->CloseNow(); |
| 408 minimized_widget_.reset(); | 418 minimized_widget_.reset(); |
| 409 } | 419 } |
| 410 } | 420 } |
| 411 | 421 |
| 412 void ScopedTransformOverviewWindow::Close() { | 422 void ScopedTransformOverviewWindow::Close() { |
| 413 if (immediate_close_for_tests) { | 423 if (immediate_close_for_tests) { |
| 414 CloseWidget(); | 424 CloseWidget(); |
| 415 return; | 425 return; |
| 416 } | 426 } |
| 417 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 427 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 418 FROM_HERE, base::Bind(&ScopedTransformOverviewWindow::CloseWidget, | 428 FROM_HERE, base::Bind(&ScopedTransformOverviewWindow::CloseWidget, |
| 419 weak_ptr_factory_.GetWeakPtr()), | 429 weak_ptr_factory_.GetWeakPtr()), |
| 420 base::TimeDelta::FromMilliseconds(kCloseWindowDelayInMilliseconds)); | 430 base::TimeDelta::FromMilliseconds(kCloseWindowDelayInMilliseconds)); |
| 421 } | 431 } |
| 422 | 432 |
| 423 void ScopedTransformOverviewWindow::PrepareForOverview() { | 433 void ScopedTransformOverviewWindow::PrepareForOverview() { |
| 424 DCHECK(!overview_started_); | 434 DCHECK(!overview_started_); |
| 425 overview_started_ = true; | 435 overview_started_ = true; |
| 426 window_->GetWindowState()->set_ignored_by_shelf(true); | 436 wm::GetWindowState(window_)->set_ignored_by_shelf(true); |
| 427 if (window_->GetShowState() == ui::SHOW_STATE_MINIMIZED) | 437 if (window_->GetProperty(aura::client::kShowStateKey) == |
| 438 ui::SHOW_STATE_MINIMIZED) { | |
| 428 CreateMirrorWindowForMinimizedState(); | 439 CreateMirrorWindowForMinimizedState(); |
| 440 } | |
| 429 } | 441 } |
| 430 | 442 |
| 431 void ScopedTransformOverviewWindow::CloseWidget() { | 443 void ScopedTransformOverviewWindow::CloseWidget() { |
| 432 WmWindow* parent_window = GetTransientRoot(window_); | 444 WmWindow* parent_window = WmWindow::Get(GetTransientRoot(window_)); |
| 433 if (parent_window) | 445 if (parent_window) |
| 434 parent_window->CloseWidget(); | 446 parent_window->CloseWidget(); |
| 435 } | 447 } |
| 436 | 448 |
| 437 // static | 449 // static |
| 438 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { | 450 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { |
| 439 immediate_close_for_tests = true; | 451 immediate_close_for_tests = true; |
| 440 } | 452 } |
| 441 | 453 |
| 442 WmWindow* ScopedTransformOverviewWindow::GetOverviewWindow() const { | 454 aura::Window* ScopedTransformOverviewWindow::GetOverviewWindow() const { |
| 443 if (minimized_widget_) | 455 if (minimized_widget_) |
| 444 return GetOverviewWindowForMinimizedState(); | 456 return GetOverviewWindowForMinimizedState(); |
| 445 return window_; | 457 return window_; |
| 446 } | 458 } |
| 447 | 459 |
| 448 void ScopedTransformOverviewWindow::EnsureVisible() { | 460 void ScopedTransformOverviewWindow::EnsureVisible() { |
| 449 original_opacity_ = 1.f; | 461 original_opacity_ = 1.f; |
| 450 } | 462 } |
| 451 | 463 |
| 452 void ScopedTransformOverviewWindow::OnGestureEvent(ui::GestureEvent* event) { | 464 void ScopedTransformOverviewWindow::OnGestureEvent(ui::GestureEvent* event) { |
| 453 if (event->type() == ui::ET_GESTURE_TAP) { | 465 if (event->type() == ui::ET_GESTURE_TAP) { |
| 454 EnsureVisible(); | 466 EnsureVisible(); |
| 455 window_->Show(); | 467 window_->Show(); |
| 456 window_->Activate(); | 468 wm::ActivateWindow(window_); |
| 457 } | 469 } |
| 458 } | 470 } |
| 459 | 471 |
| 460 void ScopedTransformOverviewWindow::OnMouseEvent(ui::MouseEvent* event) { | 472 void ScopedTransformOverviewWindow::OnMouseEvent(ui::MouseEvent* event) { |
| 461 if (event->type() == ui::ET_MOUSE_PRESSED && event->IsOnlyLeftMouseButton()) { | 473 if (event->type() == ui::ET_MOUSE_PRESSED && event->IsOnlyLeftMouseButton()) { |
| 462 EnsureVisible(); | 474 EnsureVisible(); |
| 463 window_->Show(); | 475 window_->Show(); |
| 464 window_->Activate(); | 476 wm::ActivateWindow(window_); |
| 465 } | 477 } |
| 466 } | 478 } |
| 467 | 479 |
| 468 WmWindow* ScopedTransformOverviewWindow::GetOverviewWindowForMinimizedState() | 480 aura::Window* |
| 469 const { | 481 ScopedTransformOverviewWindow::GetOverviewWindowForMinimizedState() const { |
| 470 return minimized_widget_ ? WmWindow::Get(minimized_widget_->GetNativeWindow()) | 482 return minimized_widget_ ? minimized_widget_->GetNativeWindow() : nullptr; |
| 471 : nullptr; | |
| 472 } | 483 } |
| 473 | 484 |
| 474 void ScopedTransformOverviewWindow::CreateMirrorWindowForMinimizedState() { | 485 void ScopedTransformOverviewWindow::CreateMirrorWindowForMinimizedState() { |
| 475 DCHECK(!minimized_widget_.get()); | 486 DCHECK(!minimized_widget_.get()); |
| 476 views::Widget::InitParams params; | 487 views::Widget::InitParams params; |
| 477 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 488 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 478 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 489 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 479 params.visible_on_all_workspaces = true; | 490 params.visible_on_all_workspaces = true; |
| 480 params.name = "OverviewModeMinimized"; | 491 params.name = "OverviewModeMinimized"; |
| 481 params.activatable = views::Widget::InitParams::Activatable::ACTIVATABLE_NO; | 492 params.activatable = views::Widget::InitParams::Activatable::ACTIVATABLE_NO; |
| 482 params.accept_events = true; | 493 params.accept_events = true; |
| 483 minimized_widget_.reset(new views::Widget); | 494 minimized_widget_.reset(new views::Widget); |
| 484 window_->GetRootWindow() | 495 RootWindowController::ForWindow(window_->GetRootWindow()) |
| 485 ->GetRootWindowController() | 496 ->ConfigureWidgetInitParamsForContainer(minimized_widget_.get(), |
| 486 ->ConfigureWidgetInitParamsForContainer( | 497 window_->parent()->id(), ¶ms); |
| 487 minimized_widget_.get(), window_->GetParent()->aura_window()->id(), | |
| 488 ¶ms); | |
| 489 minimized_widget_->set_focus_on_creation(false); | 498 minimized_widget_->set_focus_on_creation(false); |
| 490 minimized_widget_->Init(params); | 499 minimized_widget_->Init(params); |
| 491 | 500 |
| 492 views::View* mirror_view = new wm::WindowMirrorView(window_->aura_window()); | 501 views::View* mirror_view = new wm::WindowMirrorView(window_); |
| 493 mirror_view->SetVisible(true); | 502 mirror_view->SetVisible(true); |
| 494 mirror_view->SetTargetHandler(this); | 503 mirror_view->SetTargetHandler(this); |
| 495 minimized_widget_->SetContentsView(mirror_view); | 504 minimized_widget_->SetContentsView(mirror_view); |
| 496 gfx::Rect bounds(window_->GetBoundsInScreen()); | 505 gfx::Rect bounds(window_->GetBoundsInScreen()); |
| 497 gfx::Size preferred = mirror_view->GetPreferredSize(); | 506 gfx::Size preferred = mirror_view->GetPreferredSize(); |
| 498 // In unit tests, the content view can have empty size. | 507 // In unit tests, the content view can have empty size. |
| 499 if (!preferred.IsEmpty()) { | 508 if (!preferred.IsEmpty()) { |
| 500 int inset = bounds.height() - preferred.height(); | 509 int inset = bounds.height() - preferred.height(); |
| 501 bounds.Inset(0, 0, 0, inset); | 510 bounds.Inset(0, 0, 0, inset); |
| 502 } | 511 } |
| 503 minimized_widget_->SetBounds(bounds); | 512 minimized_widget_->SetBounds(bounds); |
| 504 minimized_widget_->Show(); | 513 minimized_widget_->Show(); |
| 505 } | 514 } |
| 506 | 515 |
| 507 } // namespace ash | 516 } // namespace ash |
| OLD | NEW |