Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: athena/wm/split_view_controller.cc

Issue 513313003: Fix crash when using title drag on a window opened while split view is active (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/wm/split_view_controller.h ('k') | athena/wm/window_manager_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "athena/wm/split_view_controller.h" 5 #include "athena/wm/split_view_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "athena/wm/public/window_list_provider.h" 9 #include "athena/wm/public/window_list_provider.h"
10 #include "athena/wm/public/window_manager.h" 10 #include "athena/wm/public/window_manager.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 CHECK(IsSplitViewModeActive()); 105 CHECK(IsSplitViewModeActive());
106 CHECK(replace_with); 106 CHECK(replace_with);
107 CHECK(window == left_window_ || window == right_window_); 107 CHECK(window == left_window_ || window == right_window_);
108 CHECK(replace_with != left_window_ && replace_with != right_window_); 108 CHECK(replace_with != left_window_ && replace_with != right_window_);
109 #if !defined(NDEBUG) 109 #if !defined(NDEBUG)
110 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 110 aura::Window::Windows windows = window_list_provider_->GetWindowList();
111 DCHECK(std::find(windows.begin(), windows.end(), replace_with) != 111 DCHECK(std::find(windows.begin(), windows.end(), replace_with) !=
112 windows.end()); 112 windows.end());
113 #endif 113 #endif
114 114
115 replace_with->SetBounds(window->bounds());
116 replace_with->SetTransform(gfx::Transform());
117 if (window == left_window_) 115 if (window == left_window_)
118 left_window_ = replace_with; 116 left_window_ = replace_with;
119 else 117 else
120 right_window_ = replace_with; 118 right_window_ = replace_with;
121 wm::ActivateWindow(replace_with); 119 wm::ActivateWindow(replace_with);
120 UpdateLayout(false);
122 window->SetTransform(gfx::Transform()); 121 window->SetTransform(gfx::Transform());
122 window->Hide();
123 } 123 }
124 124
125 void SplitViewController::DeactivateSplitMode() { 125 void SplitViewController::DeactivateSplitMode() {
126 CHECK_NE(SCROLLING, state_); 126 CHECK_NE(SCROLLING, state_);
127 state_ = INACTIVE; 127 state_ = INACTIVE;
128 UpdateLayout(false);
128 left_window_ = right_window_ = NULL; 129 left_window_ = right_window_ = NULL;
129 } 130 }
130 131
131 gfx::Rect SplitViewController::GetLeftTargetBounds() { 132 gfx::Rect SplitViewController::GetLeftTargetBounds() {
132 gfx::Rect work_area = 133 gfx::Rect work_area =
133 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); 134 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area();
134 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); 135 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height());
135 } 136 }
136 137
137 gfx::Rect SplitViewController::GetRightTargetBounds() { 138 gfx::Rect SplitViewController::GetRightTargetBounds() {
138 gfx::Rect work_area = 139 gfx::Rect work_area =
139 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); 140 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area();
140 int container_width = container_->bounds().width(); 141 int container_width = container_->bounds().width();
141 return gfx::Rect( 142 return gfx::Rect(
142 container_width / 2, 0, container_width / 2, work_area.height()); 143 container_width / 2, 0, container_width / 2, work_area.height());
143 } 144 }
144 145
145 void SplitViewController::UpdateLayout(bool animate) { 146 void SplitViewController::UpdateLayout(bool animate) {
146 if (!left_window_) 147 if (!left_window_)
147 return; 148 return;
148 CHECK(right_window_); 149 CHECK(right_window_);
149 gfx::Transform left_transform; 150
150 gfx::Transform right_transform; 151 if (state_ == INACTIVE && !animate) {
151 int container_width = container_->GetBoundsInScreen().width(); 152 if (!wm::IsActiveWindow(left_window_))
153 left_window_->Hide();
154 if (!wm::IsActiveWindow(right_window_))
155 right_window_->Hide();
sadrul 2014/08/29 19:53:53 Can you move this code with the block in line 174
pkotwicz 2014/08/29 20:18:41 Done.
156 } else {
157 left_window_->Show();
sadrul 2014/08/29 19:53:53 Do we ever call UpdateLayout() with state_ == INAC
pkotwicz 2014/08/29 20:18:40 Yes, from ScrollEnd()
158 right_window_->Show();
159 }
160
152 if (state_ == ACTIVE) { 161 if (state_ == ACTIVE) {
153 // Windows should be resized via an animation when entering the ACTIVE 162 if (animate) {
154 // state. 163 gfx::Transform left_transform = GetTargetTransformForBoundsAnimation(
155 CHECK(animate); 164 left_window_->bounds(), GetLeftTargetBounds());
156 // We scale the windows here, but when the animation finishes, we reset 165 gfx::Transform right_transform = GetTargetTransformForBoundsAnimation(
157 // the scaling and update the window bounds to the proper size - see 166 right_window_->bounds(), GetRightTargetBounds());
158 // OnAnimationCompleted(). 167 SetWindowTransforms(left_transform, right_transform, true);
159 left_transform = GetTargetTransformForBoundsAnimation( 168 } else {
160 left_window_->bounds(), GetLeftTargetBounds()); 169 left_window_->SetBounds(GetLeftTargetBounds());
161 right_transform = GetTargetTransformForBoundsAnimation( 170 right_window_->SetBounds(GetRightTargetBounds());
162 right_window_->bounds(), GetRightTargetBounds()); 171 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false);
172 }
173 } else if (state_ == INACTIVE && !animate) {
174 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false);
163 } else { 175 } else {
164 left_transform.Translate(separator_position_ - container_width, 0); 176 gfx::Transform left_transform;
sadrul 2014/08/29 19:53:53 Do we expect state_ here to always be SCROLLING? I
pkotwicz 2014/08/29 20:18:40 We do not. We want to go through here when called
177 left_transform.Translate(separator_position_ - container_->bounds().width(),
178 0);
179 gfx::Transform right_transform;
165 right_transform.Translate(separator_position_, 0); 180 right_transform.Translate(separator_position_, 0);
181 SetWindowTransforms(left_transform, right_transform, animate);
166 } 182 }
167 left_window_->Show(); 183 // Note: |left_window_| and |right_window_| may be NULL if calling
168 right_window_->Show(); 184 // SetWindowTransforms():
169 SetWindowTransform(left_window_, left_transform, animate); 185 // - caused the in-progress animation to abort.
170 SetWindowTransform(right_window_, right_transform, animate); 186 // - started a zero duration animation.
171 } 187 }
172 188
173 void SplitViewController::SetWindowTransform(aura::Window* window, 189 void SplitViewController::SetWindowTransforms(
174 const gfx::Transform& transform, 190 const gfx::Transform& left_transform,
175 bool animate) { 191 const gfx::Transform& right_transform,
192 bool animate) {
176 if (animate) { 193 if (animate) {
177 scoped_refptr<ui::LayerAnimator> animator = window->layer()->GetAnimator(); 194 ui::ScopedLayerAnimationSettings left_settings(
178 ui::ScopedLayerAnimationSettings settings(animator); 195 left_window_->layer()->GetAnimator());
179 settings.SetPreemptionStrategy( 196 left_settings.SetPreemptionStrategy(
180 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 197 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
181 settings.AddObserver(new ui::ClosureAnimationObserver( 198 left_window_->SetTransform(left_transform);
199
200 ui::ScopedLayerAnimationSettings right_settings(
201 right_window_->layer()->GetAnimator());
202 right_settings.SetPreemptionStrategy(
203 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
204 right_settings.AddObserver(new ui::ClosureAnimationObserver(
182 base::Bind(&SplitViewController::OnAnimationCompleted, 205 base::Bind(&SplitViewController::OnAnimationCompleted,
183 weak_factory_.GetWeakPtr(), 206 weak_factory_.GetWeakPtr())));
184 window))); 207 right_window_->SetTransform(right_transform);
185 window->SetTransform(transform);
186 } else { 208 } else {
187 window->SetTransform(transform); 209 left_window_->SetTransform(left_transform);
210 right_window_->SetTransform(right_transform);
188 } 211 }
189 } 212 }
190 213
191 void SplitViewController::OnAnimationCompleted(aura::Window* window) { 214 void SplitViewController::OnAnimationCompleted() {
192 // Animation can be cancelled when deactivated. 215 // Animation can be cancelled when deactivated.
193 if (left_window_ == NULL) 216 if (left_window_ == NULL)
194 return; 217 return;
195 DCHECK(window == left_window_ || window == right_window_); 218 UpdateLayout(false);
196 if (state_ == ACTIVE) { 219
197 window->SetTransform(gfx::Transform()); 220 if (state_ == INACTIVE) {
198 if (window == left_window_) 221 left_window_ = NULL;
199 left_window_->SetBounds(GetLeftTargetBounds()); 222 right_window_ = NULL;
200 else
201 right_window_->SetBounds(GetRightTargetBounds());
202 } else {
203 int container_width = container_->bounds().width();
204 window->SetTransform(gfx::Transform());
205 if (window == left_window_) {
206 if (separator_position_ == 0)
207 left_window_->Hide();
208 if (state_ == INACTIVE)
209 left_window_ = NULL;
210 } else {
211 if (separator_position_ == container_width)
212 right_window_->Hide();
213 if (state_ == INACTIVE)
214 right_window_ = NULL;
215 }
216 } 223 }
217 } 224 }
218 225
219 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { 226 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) {
220 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); 227 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_);
221 const gfx::Rect& display_bounds = 228 const gfx::Rect& display_bounds =
222 screen->GetDisplayNearestWindow(container_).bounds(); 229 screen->GetDisplayNearestWindow(container_).bounds();
223 gfx::Rect container_bounds = container_->GetBoundsInScreen(); 230 gfx::Rect container_bounds = container_->GetBoundsInScreen();
224 separator_position_ = 231 separator_position_ =
225 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() 232 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x()
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 295 }
289 296
290 bool SplitViewController::CanScroll() { 297 bool SplitViewController::CanScroll() {
291 // TODO(mfomitchev): return false in vertical orientation, in full screen. 298 // TODO(mfomitchev): return false in vertical orientation, in full screen.
292 bool result = (!IsSplitViewModeActive() && 299 bool result = (!IsSplitViewModeActive() &&
293 window_list_provider_->GetWindowList().size() >= 2); 300 window_list_provider_->GetWindowList().size() >= 2);
294 return result; 301 return result;
295 } 302 }
296 303
297 } // namespace athena 304 } // namespace athena
OLDNEW
« no previous file with comments | « athena/wm/split_view_controller.h ('k') | athena/wm/window_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698