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 "ash/screenshot_delegate.h" | 7 #include "ash/screenshot_delegate.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/wm/partial_screenshot_event_filter.h" | 10 #include "ash/wm/partial_screenshot_event_filter.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/base/events.h" | |
Daniel Erat
2012/04/16 16:48:49
nit: this should come after ui/base/cursor/cursor.
| |
13 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 | 21 |
21 PartialScreenshotView::PartialScreenshotView( | 22 PartialScreenshotView::PartialScreenshotView( |
22 ScreenshotDelegate* screenshot_delegate) | 23 ScreenshotDelegate* screenshot_delegate) |
(...skipping 26 matching lines...) Expand all Loading... | |
49 // the screen. | 50 // the screen. |
50 params.parent = Shell::GetInstance()->GetContainer( | 51 params.parent = Shell::GetInstance()->GetContainer( |
51 internal::kShellWindowId_OverlayContainer); | 52 internal::kShellWindowId_OverlayContainer); |
52 | 53 |
53 widget->Init(params); | 54 widget->Init(params); |
54 widget->SetContentsView(view); | 55 widget->SetContentsView(view); |
55 widget->SetBounds(Shell::GetRootWindow()->bounds()); | 56 widget->SetBounds(Shell::GetRootWindow()->bounds()); |
56 widget->GetNativeView()->SetName("PartialScreenshotView"); | 57 widget->GetNativeView()->SetName("PartialScreenshotView"); |
57 widget->StackAtTop(); | 58 widget->StackAtTop(); |
58 widget->Show(); | 59 widget->Show(); |
60 // Captures mouse events in case that context menu already captures the | |
61 // events. This will close the context menu. | |
62 widget->GetNativeView()->SetCapture(ui::CW_LOCK_MOUSE | ui::CW_LOCK_TOUCH); | |
59 | 63 |
60 view->set_window(widget->GetNativeWindow()); | 64 view->set_window(widget->GetNativeWindow()); |
61 Shell::GetInstance()->partial_screenshot_filter()->Activate(view); | 65 Shell::GetInstance()->partial_screenshot_filter()->Activate(view); |
62 } | 66 } |
63 | 67 |
64 void PartialScreenshotView::Cancel() { | 68 void PartialScreenshotView::Cancel() { |
65 DCHECK(window_); | 69 DCHECK(window_); |
66 window_->Hide(); | 70 window_->Hide(); |
67 Shell::GetInstance()->partial_screenshot_filter()->Deactivate(); | 71 Shell::GetInstance()->partial_screenshot_filter()->Deactivate(); |
68 MessageLoop::current()->DeleteSoon(FROM_HERE, window_); | 72 MessageLoop::current()->DeleteSoon(FROM_HERE, window_); |
69 } | 73 } |
70 | 74 |
71 gfx::NativeCursor PartialScreenshotView::GetCursor( | 75 gfx::NativeCursor PartialScreenshotView::GetCursor( |
72 const views::MouseEvent& event) { | 76 const views::MouseEvent& event) { |
73 // Always use "crosshair" cursor. | 77 // Always use "crosshair" cursor. |
74 return ui::kCursorCross; | 78 return ui::kCursorCross; |
75 } | 79 } |
76 | 80 |
77 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { | 81 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { |
78 if (is_dragging_) { | 82 if (is_dragging_) { |
79 // Screenshot area representation: black rectangle with white | 83 // Screenshot area representation: black rectangle with white |
80 // rectangle inside. | 84 // rectangle inside. |
81 gfx::Rect screenshot_rect = GetScreenshotRect(); | 85 gfx::Rect screenshot_rect = GetScreenshotRect(); |
82 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); | 86 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); |
83 screenshot_rect.Inset(1, 1, 1, 1); | 87 screenshot_rect.Inset(1, 1, 1, 1); |
84 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); | 88 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); |
85 } | 89 } |
86 } | 90 } |
87 | 91 |
92 void PartialScreenshotView::OnMouseCaptureLost() { | |
93 Cancel(); | |
94 } | |
95 | |
88 bool PartialScreenshotView::OnMousePressed(const views::MouseEvent& event) { | 96 bool PartialScreenshotView::OnMousePressed(const views::MouseEvent& event) { |
89 start_position_ = event.location(); | 97 start_position_ = event.location(); |
90 return true; | 98 return true; |
91 } | 99 } |
92 | 100 |
93 bool PartialScreenshotView::OnMouseDragged(const views::MouseEvent& event) { | 101 bool PartialScreenshotView::OnMouseDragged(const views::MouseEvent& event) { |
94 current_position_ = event.location(); | 102 current_position_ = event.location(); |
95 SchedulePaint(); | 103 SchedulePaint(); |
96 is_dragging_ = true; | 104 is_dragging_ = true; |
97 return true; | 105 return true; |
(...skipping 19 matching lines...) Expand all Loading... | |
117 | 125 |
118 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { | 126 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { |
119 int left = std::min(start_position_.x(), current_position_.x()); | 127 int left = std::min(start_position_.x(), current_position_.x()); |
120 int top = std::min(start_position_.y(), current_position_.y()); | 128 int top = std::min(start_position_.y(), current_position_.y()); |
121 int width = ::abs(start_position_.x() - current_position_.x()); | 129 int width = ::abs(start_position_.x() - current_position_.x()); |
122 int height = ::abs(start_position_.y() - current_position_.y()); | 130 int height = ::abs(start_position_.y() - current_position_.y()); |
123 return gfx::Rect(left, top, width, height); | 131 return gfx::Rect(left, top, width, height); |
124 } | 132 } |
125 | 133 |
126 } // namespace ash | 134 } // namespace ash |
OLD | NEW |