Chromium Code Reviews| 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" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 current_position_ = position; | |
|
sky
2013/03/25 23:42:29
Can this early out if is_dragging_ and current_pos
Yufeng Shen (Slow to review)
2013/03/26 01:24:03
Done.
| |
| 149 SchedulePaint(); | |
| 150 is_dragging_ = true; | |
| 151 } | |
| 152 | |
| 153 void PartialScreenshotView::OnSelectionFinished() { | |
| 154 overlay_delegate_->Cancel(); | |
| 155 if (!is_dragging_) | |
| 156 return; | |
| 157 | |
| 158 is_dragging_ = false; | |
| 159 if (screenshot_delegate_) { | |
| 160 aura::RootWindow *root_window = | |
| 161 GetWidget()->GetNativeWindow()->GetRootWindow(); | |
| 162 screenshot_delegate_->HandleTakePartialScreenshot( | |
| 163 root_window, | |
| 164 gfx::IntersectRects(root_window->bounds(), GetScreenshotRect())); | |
| 165 } | |
| 166 } | |
| 167 | |
| 143 gfx::NativeCursor PartialScreenshotView::GetCursor( | 168 gfx::NativeCursor PartialScreenshotView::GetCursor( |
| 144 const ui::MouseEvent& event) { | 169 const ui::MouseEvent& event) { |
| 145 // Always use "crosshair" cursor. | 170 // Always use "crosshair" cursor. |
| 146 return ui::kCursorCross; | 171 return ui::kCursorCross; |
| 147 } | 172 } |
| 148 | 173 |
| 149 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { | 174 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { |
| 150 if (is_dragging_) { | 175 if (is_dragging_) { |
| 151 // Screenshot area representation: black rectangle with white | 176 // Screenshot area representation: black rectangle with white |
| 152 // rectangle inside. To avoid capturing these rectangles when mouse | 177 // rectangle inside. To avoid capturing these rectangles when mouse |
| 153 // release, they should be outside of the actual capturing area. | 178 // release, they should be outside of the actual capturing area. |
| 154 gfx::Rect screenshot_rect = GetScreenshotRect(); | 179 gfx::Rect screenshot_rect = GetScreenshotRect(); |
| 155 screenshot_rect.Inset(-1, -1, -1, -1); | 180 screenshot_rect.Inset(-1, -1, -1, -1); |
| 156 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); | 181 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); |
| 157 screenshot_rect.Inset(-1, -1, -1, -1); | 182 screenshot_rect.Inset(-1, -1, -1, -1); |
| 158 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); | 183 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); |
| 159 } | 184 } |
| 160 } | 185 } |
| 161 | 186 |
| 162 bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) { | 187 bool PartialScreenshotView::OnMousePressed(const ui::MouseEvent& event) { |
| 163 // Prevent moving across displays during drag. Capturing a screenshot across | 188 // Prevent moving across displays during drag. Capturing a screenshot across |
| 164 // the displays is not supported yet. | 189 // the displays is not supported yet. |
| 165 // TODO(mukai): remove this restriction. | 190 // TODO(mukai): remove this restriction. |
| 166 internal::MouseCursorEventFilter* mouse_cursor_filter = | 191 internal::MouseCursorEventFilter* mouse_cursor_filter = |
| 167 Shell::GetInstance()->mouse_cursor_filter(); | 192 Shell::GetInstance()->mouse_cursor_filter(); |
| 168 mouse_cursor_filter->set_mouse_warp_mode( | 193 mouse_cursor_filter->set_mouse_warp_mode( |
| 169 internal::MouseCursorEventFilter::WARP_NONE); | 194 internal::MouseCursorEventFilter::WARP_NONE); |
| 170 start_position_ = event.location(); | 195 OnSelectionStarted(event.location()); |
| 171 return true; | 196 return true; |
| 172 } | 197 } |
| 173 | 198 |
| 174 bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) { | 199 bool PartialScreenshotView::OnMouseDragged(const ui::MouseEvent& event) { |
| 175 current_position_ = event.location(); | 200 OnSelectionChanged(event.location()); |
| 176 SchedulePaint(); | |
| 177 is_dragging_ = true; | |
| 178 return true; | 201 return true; |
| 179 } | 202 } |
| 180 | 203 |
| 181 bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 204 bool PartialScreenshotView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 182 // Do nothing but do not propagate events futhermore. | 205 // Do nothing but do not propagate events futhermore. |
| 183 return true; | 206 return true; |
| 184 } | 207 } |
| 185 | 208 |
| 186 void PartialScreenshotView::OnMouseReleased(const ui::MouseEvent& event) { | 209 void PartialScreenshotView::OnMouseReleased(const ui::MouseEvent& event) { |
| 187 overlay_delegate_->Cancel(); | 210 OnSelectionFinished(); |
|
sky
2013/03/25 23:42:29
What about if capture is lost?
Yufeng Shen (Slow to review)
2013/03/26 01:24:03
Added OnMouseCaptureLost() which basically cancels
| |
| 188 if (!is_dragging_) | 211 } |
| 189 return; | |
| 190 | 212 |
| 191 is_dragging_ = false; | 213 void PartialScreenshotView::OnGestureEvent(ui::GestureEvent* event) { |
| 192 if (screenshot_delegate_) { | 214 gfx::Point position = event->location(); |
|
sky
2013/03/25 23:42:29
const gfx::Point&, although you only use this in t
Yufeng Shen (Slow to review)
2013/03/26 01:24:03
Done.
| |
| 193 aura::RootWindow *root_window = | 215 switch(event->type()) { |
| 194 GetWidget()->GetNativeWindow()->GetRootWindow(); | 216 case ui::ET_GESTURE_TAP_DOWN: |
| 195 screenshot_delegate_->HandleTakePartialScreenshot( | 217 OnSelectionStarted(position); |
| 196 root_window, | 218 break; |
| 197 gfx::IntersectRects(root_window->bounds(), GetScreenshotRect())); | 219 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 220 OnSelectionChanged(position); | |
| 221 break; | |
| 222 case ui::ET_GESTURE_SCROLL_END: | |
| 223 case ui::ET_SCROLL_FLING_START: | |
| 224 OnSelectionFinished(); | |
| 225 break; | |
| 226 default: | |
| 227 break; | |
| 198 } | 228 } |
| 229 | |
| 230 event->SetHandled(); | |
| 199 } | 231 } |
| 200 | 232 |
| 201 } // namespace ash | 233 } // namespace ash |
| OLD | NEW |