diff options
Diffstat (limited to 'ash/wm')
-rw-r--r-- | ash/wm/overlay_event_filter.cc | 1 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_view.cc | 245 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_view.h | 75 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_view_unittest.cc | 122 |
4 files changed, 0 insertions, 443 deletions
diff --git a/ash/wm/overlay_event_filter.cc b/ash/wm/overlay_event_filter.cc index 2e1c998..f9594d72 100644 --- a/ash/wm/overlay_event_filter.cc +++ b/ash/wm/overlay_event_filter.cc @@ -4,7 +4,6 @@ #include "ash/wm/overlay_event_filter.h" -#include "ash/wm/partial_screenshot_view.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" #include "ui/events/event.h" diff --git a/ash/wm/partial_screenshot_view.cc b/ash/wm/partial_screenshot_view.cc deleted file mode 100644 index 233a286..0000000 --- a/ash/wm/partial_screenshot_view.cc +++ /dev/null @@ -1,245 +0,0 @@ -// 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/wm/partial_screenshot_view.h" - -#include <algorithm> - -#include "ash/display/mouse_cursor_event_filter.h" -#include "ash/screenshot_delegate.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/wm/overlay_event_filter.h" -#include "ui/aura/client/capture_client.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/base/cursor/cursor.h" -#include "ui/events/event.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/rect.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_observer.h" - -namespace ash { - -// A self-owned object to handle the cancel and the finish of current partial -// screenshot session. -class PartialScreenshotView::OverlayDelegate - : public OverlayEventFilter::Delegate, - public views::WidgetObserver { - public: - OverlayDelegate() { - Shell::GetInstance()->overlay_filter()->Activate(this); - } - - void RegisterWidget(views::Widget* widget) { - widgets_.push_back(widget); - widget->AddObserver(this); - } - - // Overridden from OverlayEventFilter::Delegate: - void Cancel() override { - // Make sure the mouse_warp_mode allows warping. It can be stopped by a - // partial screenshot view. - MouseCursorEventFilter* mouse_cursor_filter = - Shell::GetInstance()->mouse_cursor_filter(); - mouse_cursor_filter->set_mouse_warp_mode( - MouseCursorEventFilter::WARP_ALWAYS); - for (size_t i = 0; i < widgets_.size(); ++i) - widgets_[i]->Close(); - } - - bool IsCancelingKeyEvent(ui::KeyEvent* event) override { - return event->key_code() == ui::VKEY_ESCAPE; - } - - aura::Window* GetWindow() override { - // Just returns NULL because this class does not handle key events in - // OverlayEventFilter, except for cancel keys. - return NULL; - } - - // Overridden from views::WidgetObserver: - void OnWidgetDestroying(views::Widget* widget) override { - widget->RemoveObserver(this); - widgets_.erase(std::remove(widgets_.begin(), widgets_.end(), widget)); - if (widgets_.empty()) - delete this; - } - - private: - ~OverlayDelegate() override { - Shell::GetInstance()->overlay_filter()->Deactivate(this); - } - - std::vector<views::Widget*> widgets_; - - DISALLOW_COPY_AND_ASSIGN(OverlayDelegate); -}; - -// static -std::vector<PartialScreenshotView*> -PartialScreenshotView::StartPartialScreenshot( - ScreenshotDelegate* screenshot_delegate) { - std::vector<PartialScreenshotView*> views; - - if (Shell::GetInstance()->overlay_filter()->IsActive()) - return views; - - OverlayDelegate* overlay_delegate = new OverlayDelegate(); - aura::Window::Windows root_windows = Shell::GetAllRootWindows(); - for (aura::Window::Windows::iterator it = root_windows.begin(); - it != root_windows.end(); ++it) { - PartialScreenshotView* new_view = new PartialScreenshotView( - overlay_delegate, screenshot_delegate); - new_view->Init(*it); - views.push_back(new_view); - } - return views; -} - -PartialScreenshotView::PartialScreenshotView( - PartialScreenshotView::OverlayDelegate* overlay_delegate, - ScreenshotDelegate* screenshot_delegate) - : is_dragging_(false), - overlay_delegate_(overlay_delegate), - screenshot_delegate_(screenshot_delegate) { -} - -PartialScreenshotView::~PartialScreenshotView() { - overlay_delegate_ = NULL; - screenshot_delegate_ = NULL; -} - -void PartialScreenshotView::Init(aura::Window* root_window) { - views::Widget* widget = new views::Widget; - views::Widget::InitParams params( - views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; - params.delegate = this; - // The partial screenshot rectangle has to be at the real top of - // the screen. - params.parent = - Shell::GetContainer(root_window, kShellWindowId_OverlayContainer); - - widget->Init(params); - widget->SetContentsView(this); - widget->SetBounds(root_window->GetBoundsInScreen()); - widget->GetNativeView()->SetName("PartialScreenshotView"); - widget->StackAtTop(); - widget->Show(); - // Releases the mouse capture to let mouse events come to the view. This - // will close the context menu. - aura::client::CaptureClient* capture_client = - aura::client::GetCaptureClient(root_window); - if (capture_client->GetCaptureWindow()) - capture_client->ReleaseCapture(capture_client->GetCaptureWindow()); - - overlay_delegate_->RegisterWidget(widget); -} - -gfx::Rect PartialScreenshotView::GetScreenshotRect() const { - int left = std::min(start_position_.x(), current_position_.x()); - int top = std::min(start_position_.y(), current_position_.y()); - int width = ::abs(start_position_.x() - current_position_.x()); - int height = ::abs(start_position_.y() - current_position_.y()); - return gfx::Rect(left, top, width, height); -} - -void PartialScreenshotView::OnSelectionStarted(const gfx::Point& position) { - start_position_ = position; -} - -void PartialScreenshotView::OnSelectionChanged(const gfx::Point& position) { - if (is_dragging_ && current_position_ == position) - return; - current_position_ = position; - SchedulePaint(); - is_dragging_ = true; -} - -void PartialScreenshotView::OnSelectionFinished() { - overlay_delegate_->Cancel(); - if (!is_dragging_) - return; - - is_dragging_ = false; - if (screenshot_delegate_) { - aura::Window*root_window = - GetWidget()->GetNativeWindow()->GetRootWindow(); - screenshot_delegate_->HandleTakePartialScreenshot( - root_window, - gfx::IntersectRects(root_window->bounds(), GetScreenshotRect())); - } -} - -gfx::NativeCursor PartialScreenshotView::GetCursor( - const ui::MouseEvent& event) { - // Always use "crosshair" cursor. - return ui::kCursorCross; -} - -void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { - if (is_dragging_) { - // Screenshot area representation: black rectangle with white - // rectangle inside. To avoid capturing these rectangles when mouse - // release, they should be outside of the actual capturing area. - gfx::Rect screenshot_rect = GetScreenshotRect(); - screenshot_rect.Inset(-1, -1, -1, -1); - canvas->DrawRect(screenshot_rect, SK_ColorWHITE); - screenshot_rect.Inset(-1, -1, -1, -1); - canvas->DrawRect(screenshot_rect, SK_ColorBLACK); - } -} - -bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) { - // Prevent moving across displays during drag. Capturing a screenshot across - // the displays is not supported yet. - // TODO(mukai): remove this restriction. - MouseCursorEventFilter* mouse_cursor_filter = - Shell::GetInstance()->mouse_cursor_filter(); - mouse_cursor_filter->set_mouse_warp_mode(MouseCursorEventFilter::WARP_NONE); - OnSelectionStarted(event.location()); - return true; -} - -bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) { - OnSelectionChanged(event.location()); - return true; -} - -bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) { - // Do nothing but do not propagate events futhermore. - return true; -} - -void PartialScreenshotView::OnMouseReleased(const ui::MouseEvent& event) { - OnSelectionFinished(); -} - -void PartialScreenshotView::OnMouseCaptureLost() { - is_dragging_ = false; - OnSelectionFinished(); -} - -void PartialScreenshotView::OnGestureEvent(ui::GestureEvent* event) { - switch(event->type()) { - case ui::ET_GESTURE_TAP_DOWN: - OnSelectionStarted(event->location()); - break; - case ui::ET_GESTURE_SCROLL_UPDATE: - OnSelectionChanged(event->location()); - break; - case ui::ET_GESTURE_SCROLL_END: - case ui::ET_SCROLL_FLING_START: - OnSelectionFinished(); - break; - default: - break; - } - - event->SetHandled(); -} - -} // namespace ash diff --git a/ash/wm/partial_screenshot_view.h b/ash/wm/partial_screenshot_view.h deleted file mode 100644 index 71e0242..0000000 --- a/ash/wm/partial_screenshot_view.h +++ /dev/null @@ -1,75 +0,0 @@ -// 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. - -#ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ -#define ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ - -#include <vector> - -#include "ash/ash_export.h" -#include "base/compiler_specific.h" -#include "base/gtest_prod_util.h" -#include "ui/gfx/point.h" -#include "ui/views/widget/widget_delegate.h" - -namespace ash { -class ScreenshotDelegate; - -// The view of taking partial screenshot, i.e.: drawing region -// rectangles during drag, and changing the mouse cursor to indicate -// the current mode. -class ASH_EXPORT PartialScreenshotView : public views::WidgetDelegateView { - public: - // Starts the UI for taking partial screenshot; dragging to select a region. - // PartialScreenshotViews manage their own lifetime so caller must not delete - // the returned PartialScreenshotViews. - static std::vector<PartialScreenshotView*> - StartPartialScreenshot(ScreenshotDelegate* screenshot_delegate); - - private: - FRIEND_TEST_ALL_PREFIXES(PartialScreenshotViewTest, BasicMouse); - FRIEND_TEST_ALL_PREFIXES(PartialScreenshotViewTest, BasicTouch); - - class OverlayDelegate; - - PartialScreenshotView(OverlayDelegate* overlay_delegate, - ScreenshotDelegate* screenshot_delegate); - ~PartialScreenshotView() override; - - // Initializes partial screenshot UI widget for |root_window|. - void Init(aura::Window* root_window); - - // Returns the currently selected region. - gfx::Rect GetScreenshotRect() const; - - void OnSelectionStarted(const gfx::Point& position); - void OnSelectionChanged(const gfx::Point& position); - void OnSelectionFinished(); - - // Overridden from views::View: - gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; - void OnPaint(gfx::Canvas* canvas) override; - bool OnMousePressed(const ui::MouseEvent& event) override; - bool OnMouseDragged(const ui::MouseEvent& event) override; - bool OnMouseWheel(const ui::MouseWheelEvent& event) override; - void OnMouseReleased(const ui::MouseEvent& event) override; - void OnMouseCaptureLost() override; - void OnGestureEvent(ui::GestureEvent* event) override; - - bool is_dragging_; - gfx::Point start_position_; - gfx::Point current_position_; - - // The delegate to receive Cancel. No ownership. - OverlayDelegate* overlay_delegate_; - - // ScreenshotDelegate to take the actual screenshot. No ownership. - ScreenshotDelegate* screenshot_delegate_; - - DISALLOW_COPY_AND_ASSIGN(PartialScreenshotView); -}; - -} // namespace ash - -#endif // #ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ diff --git a/ash/wm/partial_screenshot_view_unittest.cc b/ash/wm/partial_screenshot_view_unittest.cc deleted file mode 100644 index 6a31968..0000000 --- a/ash/wm/partial_screenshot_view_unittest.cc +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2013 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/wm/partial_screenshot_view.h" - -#include "ash/screenshot_delegate.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_overlay_delegate.h" -#include "ash/test/test_screenshot_delegate.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/events/test/event_generator.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_observer.h" - -namespace ash { - -class PartialScreenshotViewTest : public test::AshTestBase, - public views::WidgetObserver { - public: - PartialScreenshotViewTest() : view_(NULL) {} - ~PartialScreenshotViewTest() override { - if (view_) - view_->GetWidget()->RemoveObserver(this); - } - - void StartPartialScreenshot() { - std::vector<PartialScreenshotView*> views = - PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate()); - if (!views.empty()) { - view_ = views[0]; - view_->GetWidget()->AddObserver(this); - } - } - - protected: - PartialScreenshotView* view_; - - private: - // views::WidgetObserver: - void OnWidgetDestroying(views::Widget* widget) override { - if (view_ && view_->GetWidget() == widget) - view_ = NULL; - widget->RemoveObserver(this); - } - - DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest); -}; - -TEST_F(PartialScreenshotViewTest, BasicMouse) { - StartPartialScreenshot(); - ASSERT_TRUE(view_); - - ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - - generator.MoveMouseTo(100, 100); - generator.PressLeftButton(); - EXPECT_FALSE(view_->is_dragging_); - EXPECT_EQ("100,100", view_->start_position_.ToString()); - - generator.MoveMouseTo(200, 200); - EXPECT_TRUE(view_->is_dragging_); - EXPECT_EQ("200,200", view_->current_position_.ToString()); - - generator.ReleaseLeftButton(); - EXPECT_FALSE(view_->is_dragging_); - EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); - EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); -} - -TEST_F(PartialScreenshotViewTest, BasicTouch) { - StartPartialScreenshot(); - ASSERT_TRUE(view_); - - ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - - generator.set_current_location(gfx::Point(100,100)); - generator.GestureTapDownAndUp(gfx::Point(100,100)); - EXPECT_FALSE(view_->is_dragging_); - EXPECT_EQ(0, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); - - generator.PressTouch(); - EXPECT_FALSE(view_->is_dragging_); - EXPECT_EQ("100,100", view_->start_position_.ToString()); - - generator.MoveTouch(gfx::Point(200, 200)); - EXPECT_TRUE(view_->is_dragging_); - EXPECT_EQ("200,200", view_->current_position_.ToString()); - - generator.ReleaseTouch(); - EXPECT_FALSE(view_->is_dragging_); - EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); - EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); -} - -// Partial screenshot session should not start when there is already another -// overlay. See: http://crbug.com/341958 -TEST_F(PartialScreenshotViewTest, DontStartOverOverlay) { - OverlayEventFilter* overlay_filter = Shell::GetInstance()->overlay_filter(); - test::TestOverlayDelegate delegate; - overlay_filter->Activate(&delegate); - EXPECT_EQ(&delegate, overlay_filter->delegate_); - - StartPartialScreenshot(); - EXPECT_TRUE(view_ == NULL); - EXPECT_EQ(&delegate, overlay_filter->delegate_); - overlay_filter->Deactivate(&delegate); - - StartPartialScreenshot(); - EXPECT_TRUE(view_ != NULL); - - // Someone else attempts to activate the overlay session, which should cancel - // the current partial screenshot session. - overlay_filter->Activate(&delegate); - RunAllPendingInMessageLoop(); - EXPECT_EQ(&delegate, overlay_filter->delegate_); - EXPECT_TRUE(view_ == NULL); -} - -} // namespace ash |