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

Unified Diff: athena/wm/split_view_controller.cc

Issue 488153003: Fix crash when dragging a half width window to split view from overivew mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: athena/wm/split_view_controller.cc
diff --git a/athena/wm/split_view_controller.cc b/athena/wm/split_view_controller.cc
index cf39f2e0c60d44af99ccb6f571a4192a13640a48..e36b7a94e05623cbabd35e45564bdb0f691ae6e1 100644
--- a/athena/wm/split_view_controller.cc
+++ b/athena/wm/split_view_controller.cc
@@ -20,6 +20,21 @@
namespace athena {
+namespace {
+
+// Returns a target transform which is suitable for animating a windows's
+// bounds.
+gfx::Transform GetTargetTransformForBoundsAnimation(const gfx::Rect& from,
+ const gfx::Rect& to) {
+ gfx::Transform transform;
+ transform.Translate(to.x() - from.x(), to.y() - from.y());
+ transform.Scale(to.width() / static_cast<float>(from.width()),
+ to.height() / static_cast<float>(from.height()));
+ return transform;
+}
+
+} // namespace
+
SplitViewController::SplitViewController(
aura::Window* container,
WindowListProvider* window_list_provider)
@@ -113,6 +128,20 @@ void SplitViewController::DeactivateSplitMode() {
left_window_ = right_window_ = NULL;
}
+gfx::Rect SplitViewController::GetLeftTargetBounds() {
+ gfx::Rect work_area =
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area();
+ return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height());
+}
+
+gfx::Rect SplitViewController::GetRightTargetBounds() {
+ gfx::Rect work_area =
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area();
+ int container_width = container_->bounds().width();
+ return gfx::Rect(
+ container_width / 2, 0, container_width / 2, work_area.height());
+}
+
void SplitViewController::UpdateLayout(bool animate) {
if (!left_window_)
return;
@@ -121,19 +150,16 @@ void SplitViewController::UpdateLayout(bool animate) {
gfx::Transform right_transform;
int container_width = container_->GetBoundsInScreen().width();
if (state_ == ACTIVE) {
- // This method should only be called once in ACTIVE state when
- // the left and rightwindows are still full screen and need to be resized.
- CHECK_EQ(left_window_->bounds().width(), container_width);
- CHECK_EQ(right_window_->bounds().width(), container_width);
// Windows should be resized via an animation when entering the ACTIVE
// state.
CHECK(animate);
// We scale the windows here, but when the animation finishes, we reset
// the scaling and update the window bounds to the proper size - see
// OnAnimationCompleted().
- left_transform.Scale(.5, 1);
- right_transform.Scale(.5, 1);
- right_transform.Translate(container_width, 0);
+ left_transform = GetTargetTransformForBoundsAnimation(
+ left_window_->bounds(), GetLeftTargetBounds());
+ right_transform = GetTargetTransformForBoundsAnimation(
+ right_window_->bounds(), GetRightTargetBounds());
} else {
left_transform.Translate(separator_position_ - container_width, 0);
right_transform.Translate(separator_position_, 0);
@@ -168,16 +194,11 @@ void SplitViewController::OnAnimationCompleted(aura::Window* window) {
return;
DCHECK(window == left_window_ || window == right_window_);
if (state_ == ACTIVE) {
- gfx::Rect window_bounds = gfx::Rect(container_->bounds().size());
- int container_width = window_bounds.width();
- window_bounds.set_width(container_width / 2);
window->SetTransform(gfx::Transform());
- if (window == left_window_) {
- left_window_->SetBounds(window_bounds);
- } else {
- window_bounds.set_x(container_width / 2);
- right_window_->SetBounds(window_bounds);
- }
+ if (window == left_window_)
+ left_window_->SetBounds(GetLeftTargetBounds());
+ else
+ right_window_->SetBounds(GetRightTargetBounds());
} else {
int container_width = container_->bounds().width();
window->SetTransform(gfx::Transform());

Powered by Google App Engine
This is Rietveld 408576698