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 "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" | |
| 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 // TODO(mukai): introduce stacking mechanism to capture window to | |
|
sky
2012/04/12 15:30:45
To have menus stay on screen in this scenario will
Jun Mukai
2012/04/13 06:11:28
Then, removed the TODO.
| |
| 63 // prevent closing menus. | |
| 64 widget->GetNativeView()->SetCapture(ui::CW_LOCK_MOUSE | ui::CW_LOCK_TOUCH); | |
| 59 | 65 |
| 60 view->set_window(widget->GetNativeWindow()); | 66 view->set_window(widget->GetNativeWindow()); |
| 61 Shell::GetInstance()->partial_screenshot_filter()->Activate(view); | 67 Shell::GetInstance()->partial_screenshot_filter()->Activate(view); |
| 62 } | 68 } |
| 63 | 69 |
| 64 void PartialScreenshotView::Cancel() { | 70 void PartialScreenshotView::Cancel() { |
| 65 DCHECK(window_); | 71 DCHECK(window_); |
| 66 window_->Hide(); | 72 window_->Hide(); |
| 67 Shell::GetInstance()->partial_screenshot_filter()->Deactivate(); | 73 Shell::GetInstance()->partial_screenshot_filter()->Deactivate(); |
| 68 MessageLoop::current()->DeleteSoon(FROM_HERE, window_); | 74 MessageLoop::current()->DeleteSoon(FROM_HERE, window_); |
| 69 } | 75 } |
| 70 | 76 |
| 71 gfx::NativeCursor PartialScreenshotView::GetCursor( | 77 gfx::NativeCursor PartialScreenshotView::GetCursor( |
| 72 const views::MouseEvent& event) { | 78 const views::MouseEvent& event) { |
| 73 // Always use "crosshair" cursor. | 79 // Always use "crosshair" cursor. |
| 74 return ui::kCursorCross; | 80 return ui::kCursorCross; |
| 75 } | 81 } |
| 76 | 82 |
| 77 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { | 83 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { |
| 78 if (is_dragging_) { | 84 if (is_dragging_) { |
| 79 // Screenshot area representation: black rectangle with white | 85 // Screenshot area representation: black rectangle with white |
| 80 // rectangle inside. | 86 // rectangle inside. |
| 81 gfx::Rect screenshot_rect = GetScreenshotRect(); | 87 gfx::Rect screenshot_rect = GetScreenshotRect(); |
| 82 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); | 88 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); |
| 83 screenshot_rect.Inset(1, 1, 1, 1); | 89 screenshot_rect.Inset(1, 1, 1, 1); |
| 84 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); | 90 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); |
| 85 } | 91 } |
| 86 } | 92 } |
| 87 | 93 |
| 94 void PartialScreenshotView::OnMouseCaptureLost() { | |
| 95 Cancel(); | |
| 96 } | |
| 97 | |
| 88 bool PartialScreenshotView::OnMousePressed(const views::MouseEvent& event) { | 98 bool PartialScreenshotView::OnMousePressed(const views::MouseEvent& event) { |
| 89 start_position_ = event.location(); | 99 start_position_ = event.location(); |
| 90 return true; | 100 return true; |
| 91 } | 101 } |
| 92 | 102 |
| 93 bool PartialScreenshotView::OnMouseDragged(const views::MouseEvent& event) { | 103 bool PartialScreenshotView::OnMouseDragged(const views::MouseEvent& event) { |
| 94 current_position_ = event.location(); | 104 current_position_ = event.location(); |
| 95 SchedulePaint(); | 105 SchedulePaint(); |
| 96 is_dragging_ = true; | 106 is_dragging_ = true; |
| 97 return true; | 107 return true; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 117 | 127 |
| 118 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { | 128 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { |
| 119 int left = std::min(start_position_.x(), current_position_.x()); | 129 int left = std::min(start_position_.x(), current_position_.x()); |
| 120 int top = std::min(start_position_.y(), current_position_.y()); | 130 int top = std::min(start_position_.y(), current_position_.y()); |
| 121 int width = ::abs(start_position_.x() - current_position_.x()); | 131 int width = ::abs(start_position_.x() - current_position_.x()); |
| 122 int height = ::abs(start_position_.y() - current_position_.y()); | 132 int height = ::abs(start_position_.y() - current_position_.y()); |
| 123 return gfx::Rect(left, top, width, height); | 133 return gfx::Rect(left, top, width, height); |
| 124 } | 134 } |
| 125 | 135 |
| 126 } // namespace ash | 136 } // namespace ash |
| OLD | NEW |