OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/partial_screenshot_view.h" | 5 #include "ash/wm/partial_screenshot_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/display/mouse_cursor_event_filter.h" | 9 #include "ash/display/mouse_cursor_event_filter.h" |
10 #include "ash/screenshot_delegate.h" | 10 #include "ash/screenshot_delegate.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
13 #include "ash/wm/overlay_event_filter.h" | 13 #include "ash/wm/overlay_event_filter.h" |
14 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/base/cursor/cursor.h" | 16 #include "ui/base/cursor/cursor.h" |
17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
18 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 #include "ui/views/widget/widget_observer.h" | 22 #include "ui/views/widget/widget_observer.h" |
23 | 23 |
24 namespace ash { | 24 namespace ash { |
25 | 25 |
26 // A self-owned object to handle the cancel and the finish of current partial | 26 // A self-owned object to handle the cancel and the finish of current partial |
27 // screenshot session. | 27 // screenshot session. |
28 class PartialScreenshotView::OverlayDelegate | 28 class PartialScreenshotView::OverlayDelegate |
29 : public internal::OverlayEventFilter::Delegate, | 29 : public OverlayEventFilter::Delegate, |
30 public views::WidgetObserver { | 30 public views::WidgetObserver { |
31 public: | 31 public: |
32 OverlayDelegate() { | 32 OverlayDelegate() { |
33 Shell::GetInstance()->overlay_filter()->Activate(this); | 33 Shell::GetInstance()->overlay_filter()->Activate(this); |
34 } | 34 } |
35 | 35 |
36 void RegisterWidget(views::Widget* widget) { | 36 void RegisterWidget(views::Widget* widget) { |
37 widgets_.push_back(widget); | 37 widgets_.push_back(widget); |
38 widget->AddObserver(this); | 38 widget->AddObserver(this); |
39 } | 39 } |
40 | 40 |
41 // Overridden from OverlayEventFilter::Delegate: | 41 // Overridden from OverlayEventFilter::Delegate: |
42 virtual void Cancel() OVERRIDE { | 42 virtual void Cancel() OVERRIDE { |
43 // Make sure the mouse_warp_mode allows warping. It can be stopped by a | 43 // Make sure the mouse_warp_mode allows warping. It can be stopped by a |
44 // partial screenshot view. | 44 // partial screenshot view. |
45 internal::MouseCursorEventFilter* mouse_cursor_filter = | 45 MouseCursorEventFilter* mouse_cursor_filter = |
46 Shell::GetInstance()->mouse_cursor_filter(); | 46 Shell::GetInstance()->mouse_cursor_filter(); |
47 mouse_cursor_filter->set_mouse_warp_mode( | 47 mouse_cursor_filter->set_mouse_warp_mode( |
48 internal::MouseCursorEventFilter::WARP_ALWAYS); | 48 MouseCursorEventFilter::WARP_ALWAYS); |
49 for (size_t i = 0; i < widgets_.size(); ++i) | 49 for (size_t i = 0; i < widgets_.size(); ++i) |
50 widgets_[i]->Close(); | 50 widgets_[i]->Close(); |
51 } | 51 } |
52 | 52 |
53 virtual bool IsCancelingKeyEvent(ui::KeyEvent* event) OVERRIDE { | 53 virtual bool IsCancelingKeyEvent(ui::KeyEvent* event) OVERRIDE { |
54 return event->key_code() == ui::VKEY_ESCAPE; | 54 return event->key_code() == ui::VKEY_ESCAPE; |
55 } | 55 } |
56 | 56 |
57 virtual aura::Window* GetWindow() OVERRIDE { | 57 virtual aura::Window* GetWindow() OVERRIDE { |
58 // Just returns NULL because this class does not handle key events in | 58 // Just returns NULL because this class does not handle key events in |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 void PartialScreenshotView::Init(aura::Window* root_window) { | 111 void PartialScreenshotView::Init(aura::Window* root_window) { |
112 views::Widget* widget = new views::Widget; | 112 views::Widget* widget = new views::Widget; |
113 views::Widget::InitParams params( | 113 views::Widget::InitParams params( |
114 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 114 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
115 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 115 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
116 params.delegate = this; | 116 params.delegate = this; |
117 // The partial screenshot rectangle has to be at the real top of | 117 // The partial screenshot rectangle has to be at the real top of |
118 // the screen. | 118 // the screen. |
119 params.parent = Shell::GetContainer( | 119 params.parent = |
120 root_window, | 120 Shell::GetContainer(root_window, kShellWindowId_OverlayContainer); |
121 internal::kShellWindowId_OverlayContainer); | |
122 | 121 |
123 widget->Init(params); | 122 widget->Init(params); |
124 widget->SetContentsView(this); | 123 widget->SetContentsView(this); |
125 widget->SetBounds(root_window->GetBoundsInScreen()); | 124 widget->SetBounds(root_window->GetBoundsInScreen()); |
126 widget->GetNativeView()->SetName("PartialScreenshotView"); | 125 widget->GetNativeView()->SetName("PartialScreenshotView"); |
127 widget->StackAtTop(); | 126 widget->StackAtTop(); |
128 widget->Show(); | 127 widget->Show(); |
129 // Releases the mouse capture to let mouse events come to the view. This | 128 // Releases the mouse capture to let mouse events come to the view. This |
130 // will close the context menu. | 129 // will close the context menu. |
131 aura::client::CaptureClient* capture_client = | 130 aura::client::CaptureClient* capture_client = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); | 186 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); |
188 screenshot_rect.Inset(-1, -1, -1, -1); | 187 screenshot_rect.Inset(-1, -1, -1, -1); |
189 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); | 188 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); |
190 } | 189 } |
191 } | 190 } |
192 | 191 |
193 bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) { | 192 bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) { |
194 // Prevent moving across displays during drag. Capturing a screenshot across | 193 // Prevent moving across displays during drag. Capturing a screenshot across |
195 // the displays is not supported yet. | 194 // the displays is not supported yet. |
196 // TODO(mukai): remove this restriction. | 195 // TODO(mukai): remove this restriction. |
197 internal::MouseCursorEventFilter* mouse_cursor_filter = | 196 MouseCursorEventFilter* mouse_cursor_filter = |
198 Shell::GetInstance()->mouse_cursor_filter(); | 197 Shell::GetInstance()->mouse_cursor_filter(); |
199 mouse_cursor_filter->set_mouse_warp_mode( | 198 mouse_cursor_filter->set_mouse_warp_mode(MouseCursorEventFilter::WARP_NONE); |
200 internal::MouseCursorEventFilter::WARP_NONE); | |
201 OnSelectionStarted(event.location()); | 199 OnSelectionStarted(event.location()); |
202 return true; | 200 return true; |
203 } | 201 } |
204 | 202 |
205 bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) { | 203 bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) { |
206 OnSelectionChanged(event.location()); | 204 OnSelectionChanged(event.location()); |
207 return true; | 205 return true; |
208 } | 206 } |
209 | 207 |
210 bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 208 bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
(...skipping 23 matching lines...) Expand all Loading... |
234 OnSelectionFinished(); | 232 OnSelectionFinished(); |
235 break; | 233 break; |
236 default: | 234 default: |
237 break; | 235 break; |
238 } | 236 } |
239 | 237 |
240 event->SetHandled(); | 238 event->SetHandled(); |
241 } | 239 } |
242 | 240 |
243 } // namespace ash | 241 } // namespace ash |
OLD | NEW |