diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-01 00:40:40 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-01 00:40:40 +0000 |
commit | 8b7ba87b074c458fe7b1b6aa3e4a2a663729621a (patch) | |
tree | fee2d4aa25547fef5a42fa340dd8e7ea7023092e /ash/display/shared_display_edge_indicator.cc | |
parent | eb7956341bd8835c5f9254e62638f8635f7c268f (diff) | |
download | chromium_src-8b7ba87b074c458fe7b1b6aa3e4a2a663729621a.zip chromium_src-8b7ba87b074c458fe7b1b6aa3e4a2a663729621a.tar.gz chromium_src-8b7ba87b074c458fe7b1b6aa3e4a2a663729621a.tar.bz2 |
Allow "snapping" while dragging a window to another display
by reserving the corner that blocks pass through.
Cleanup:
Move the code that handle warp from DisplayCotnroller to MouseCursorEventFilter.
Removed unnecesary namespace, dead code.
BUG=143289
TEST=added new tests. manual=connect external monitor and drag a window to another display. a warp hole will be shown at the edge where you can drag a window into. Dragging to other place should start snapping operation.
Review URL: https://chromiumcodereview.appspot.com/10899034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display/shared_display_edge_indicator.cc')
-rw-r--r-- | ash/display/shared_display_edge_indicator.cc | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/ash/display/shared_display_edge_indicator.cc b/ash/display/shared_display_edge_indicator.cc new file mode 100644 index 0000000..1f596d0 --- /dev/null +++ b/ash/display/shared_display_edge_indicator.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/display/shared_display_edge_indicator.h" + +#include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/wm/coordinate_conversion.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/aura/client/screen_position_client.h" +#include "ui/base/animation/throb_animation.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/display.h" +#include "ui/gfx/screen.h" +#include "ui/views/painter.h" +#include "ui/views/widget/widget.h" + +namespace ash { +namespace internal { +namespace { + +const int kIndicatorAnimationDurationMs = 1000; + +views::Widget* CreateWidget(const gfx::Rect& bounds) { + // This is just a placeholder and we'll use an image. + views::Painter* painter = views::Painter::CreateHorizontalGradient( + SK_ColorWHITE, SK_ColorWHITE); + + views::Widget* widget = new views::Widget; + views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); + params.transparent = true; + params.can_activate = false; + params.keep_on_top = true; + widget->set_focus_on_creation(false); + widget->Init(params); + widget->SetVisibilityChangedAnimationsEnabled(false); + widget->GetNativeWindow()->SetName("SharedEdgeIndicator"); + views::View* content_view = new views::View; + content_view->set_background( + views::Background::CreateBackgroundPainter(true, painter)); + widget->SetContentsView(content_view); + gfx::Display display = gfx::Screen::GetDisplayMatching(bounds); + aura::Window* window = widget->GetNativeWindow(); + aura::client::ScreenPositionClient* screen_position_client = + aura::client::GetScreenPositionClient(window->GetRootWindow()); + screen_position_client->SetBounds(window, bounds, display); + widget->SetOpacity(0); + widget->Show(); + return widget; +} + +} // namespace + +SharedDisplayEdgeIndicator::SharedDisplayEdgeIndicator() + : src_widget_(NULL), + dst_widget_(NULL) { +} + +SharedDisplayEdgeIndicator::~SharedDisplayEdgeIndicator() { + Hide(); +} + +void SharedDisplayEdgeIndicator::Show(const gfx::Rect& src_bounds, + const gfx::Rect& dst_bounds) { + DCHECK(!src_widget_); + DCHECK(!dst_widget_); + src_widget_ = CreateWidget(src_bounds); + dst_widget_ = CreateWidget(dst_bounds); + animation_.reset(new ui::ThrobAnimation(this)); + animation_->SetThrobDuration(kIndicatorAnimationDurationMs); + animation_->StartThrobbing(-1 /* infinite */); +} + +void SharedDisplayEdgeIndicator::Hide() { + if (src_widget_) + src_widget_->Close(); + src_widget_ = NULL; + if (dst_widget_) + dst_widget_->Close(); + dst_widget_ = NULL; +} + +void SharedDisplayEdgeIndicator::AnimationProgressed( + const ui::Animation* animation) { + int opacity = animation->CurrentValueBetween(0, 255); + if (src_widget_) + src_widget_->SetOpacity(opacity); + if (dst_widget_) + dst_widget_->SetOpacity(opacity); +} + +} // namespace internal +} // namespace ash |