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

Side by Side Diff: ash/wm/partial_screenshot_view.cc

Issue 13006010: Add support for taking partial screenshot using touch (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cancel taking screenshot when OnMouseCaptureLost() Created 7 years, 9 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 unified diff | Download patch
OLDNEW
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"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 134
135 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { 135 gfx::Rect PartialScreenshotView::GetScreenshotRect() const {
136 int left = std::min(start_position_.x(), current_position_.x()); 136 int left = std::min(start_position_.x(), current_position_.x());
137 int top = std::min(start_position_.y(), current_position_.y()); 137 int top = std::min(start_position_.y(), current_position_.y());
138 int width = ::abs(start_position_.x() - current_position_.x()); 138 int width = ::abs(start_position_.x() - current_position_.x());
139 int height = ::abs(start_position_.y() - current_position_.y()); 139 int height = ::abs(start_position_.y() - current_position_.y());
140 return gfx::Rect(left, top, width, height); 140 return gfx::Rect(left, top, width, height);
141 } 141 }
142 142
143 void PartialScreenshotView::OnSelectionStarted(const gfx::Point& position) {
144 start_position_ = position;
145 }
146
147 void PartialScreenshotView::OnSelectionChanged(const gfx::Point& position) {
148 if (is_dragging_ && current_position_ == position)
149 return;
150 current_position_ = position;
151 SchedulePaint();
152 is_dragging_ = true;
153 }
154
155 void PartialScreenshotView::OnSelectionFinished() {
156 overlay_delegate_->Cancel();
157 if (!is_dragging_)
158 return;
159
160 is_dragging_ = false;
161 if (screenshot_delegate_) {
162 aura::RootWindow *root_window =
163 GetWidget()->GetNativeWindow()->GetRootWindow();
164 screenshot_delegate_->HandleTakePartialScreenshot(
165 root_window,
166 gfx::IntersectRects(root_window->bounds(), GetScreenshotRect()));
167 }
168 }
169
143 gfx::NativeCursor PartialScreenshotView::GetCursor( 170 gfx::NativeCursor PartialScreenshotView::GetCursor(
144 const ui::MouseEvent& event) { 171 const ui::MouseEvent& event) {
145 // Always use "crosshair" cursor. 172 // Always use "crosshair" cursor.
146 return ui::kCursorCross; 173 return ui::kCursorCross;
147 } 174 }
148 175
149 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { 176 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) {
150 if (is_dragging_) { 177 if (is_dragging_) {
151 // Screenshot area representation: black rectangle with white 178 // Screenshot area representation: black rectangle with white
152 // rectangle inside. To avoid capturing these rectangles when mouse 179 // rectangle inside. To avoid capturing these rectangles when mouse
153 // release, they should be outside of the actual capturing area. 180 // release, they should be outside of the actual capturing area.
154 gfx::Rect screenshot_rect = GetScreenshotRect(); 181 gfx::Rect screenshot_rect = GetScreenshotRect();
155 screenshot_rect.Inset(-1, -1, -1, -1); 182 screenshot_rect.Inset(-1, -1, -1, -1);
156 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); 183 canvas->DrawRect(screenshot_rect, SK_ColorWHITE);
157 screenshot_rect.Inset(-1, -1, -1, -1); 184 screenshot_rect.Inset(-1, -1, -1, -1);
158 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); 185 canvas->DrawRect(screenshot_rect, SK_ColorBLACK);
159 } 186 }
160 } 187 }
161 188
162 bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) { 189 bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) {
163 // Prevent moving across displays during drag. Capturing a screenshot across 190 // Prevent moving across displays during drag. Capturing a screenshot across
164 // the displays is not supported yet. 191 // the displays is not supported yet.
165 // TODO(mukai): remove this restriction. 192 // TODO(mukai): remove this restriction.
166 internal::MouseCursorEventFilter* mouse_cursor_filter = 193 internal::MouseCursorEventFilter* mouse_cursor_filter =
167 Shell::GetInstance()->mouse_cursor_filter(); 194 Shell::GetInstance()->mouse_cursor_filter();
168 mouse_cursor_filter->set_mouse_warp_mode( 195 mouse_cursor_filter->set_mouse_warp_mode(
169 internal::MouseCursorEventFilter::WARP_NONE); 196 internal::MouseCursorEventFilter::WARP_NONE);
170 start_position_ = event.location(); 197 OnSelectionStarted(event.location());
171 return true; 198 return true;
172 } 199 }
173 200
174 bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) { 201 bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) {
175 current_position_ = event.location(); 202 OnSelectionChanged(event.location());
176 SchedulePaint();
177 is_dragging_ = true;
178 return true; 203 return true;
179 } 204 }
180 205
181 bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) { 206 bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) {
182 // Do nothing but do not propagate events futhermore. 207 // Do nothing but do not propagate events futhermore.
183 return true; 208 return true;
184 } 209 }
185 210
186 void PartialScreenshotView::OnMouseReleased(const ui::MouseEvent& event) { 211 void PartialScreenshotView::OnMouseReleased(const ui::MouseEvent& event) {
187 overlay_delegate_->Cancel(); 212 OnSelectionFinished();
188 if (!is_dragging_) 213 }
189 return;
190 214
215 void PartialScreenshotView::OnMouseCaptureLost() {
191 is_dragging_ = false; 216 is_dragging_ = false;
192 if (screenshot_delegate_) { 217 OnSelectionFinished();
193 aura::RootWindow *root_window = 218 }
194 GetWidget()->GetNativeWindow()->GetRootWindow(); 219
195 screenshot_delegate_->HandleTakePartialScreenshot( 220 void PartialScreenshotView::OnGestureEvent(ui::GestureEvent* event) {
196 root_window, 221 switch(event->type()) {
197 gfx::IntersectRects(root_window->bounds(), GetScreenshotRect())); 222 case ui::ET_GESTURE_TAP_DOWN:
223 OnSelectionStarted(event->location());
224 break;
225 case ui::ET_GESTURE_SCROLL_UPDATE:
226 OnSelectionChanged(event->location());
227 break;
228 case ui::ET_GESTURE_SCROLL_END:
229 case ui::ET_SCROLL_FLING_START:
230 OnSelectionFinished();
231 break;
232 default:
233 break;
198 } 234 }
235
236 event->SetHandled();
199 } 237 }
200 238
201 } // namespace ash 239 } // namespace ash
OLDNEW
« ash/wm/partial_screenshot_view.h ('K') | « ash/wm/partial_screenshot_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698