| 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/overlay_event_filter.h" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 | 19 |
| 20 PartialScreenshotView::PartialScreenshotView( | 20 PartialScreenshotView::PartialScreenshotView( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 widget->Init(params); | 47 widget->Init(params); |
| 48 widget->SetContentsView(view); | 48 widget->SetContentsView(view); |
| 49 widget->SetBounds(root_window->bounds()); | 49 widget->SetBounds(root_window->bounds()); |
| 50 widget->GetNativeView()->SetName("PartialScreenshotView"); | 50 widget->GetNativeView()->SetName("PartialScreenshotView"); |
| 51 widget->StackAtTop(); | 51 widget->StackAtTop(); |
| 52 widget->Show(); | 52 widget->Show(); |
| 53 // Captures mouse events in case that context menu already captures the | 53 // Captures mouse events in case that context menu already captures the |
| 54 // events. This will close the context menu. | 54 // events. This will close the context menu. |
| 55 widget->GetNativeView()->SetCapture(); | 55 widget->GetNativeView()->SetCapture(); |
| 56 | 56 |
| 57 Shell::GetInstance()->partial_screenshot_filter()->Activate(view); | 57 Shell::GetInstance()->overlay_filter()->Activate(view); |
| 58 } | |
| 59 | |
| 60 void PartialScreenshotView::Cancel() { | |
| 61 Shell::GetInstance()->partial_screenshot_filter()->Deactivate(); | |
| 62 views::Widget* widget = GetWidget(); | |
| 63 if (widget) | |
| 64 widget->Close(); | |
| 65 } | 58 } |
| 66 | 59 |
| 67 gfx::NativeCursor PartialScreenshotView::GetCursor( | 60 gfx::NativeCursor PartialScreenshotView::GetCursor( |
| 68 const views::MouseEvent& event) { | 61 const views::MouseEvent& event) { |
| 69 // Always use "crosshair" cursor. | 62 // Always use "crosshair" cursor. |
| 70 return ui::kCursorCross; | 63 return ui::kCursorCross; |
| 71 } | 64 } |
| 72 | 65 |
| 66 void PartialScreenshotView::Cancel() { |
| 67 Shell::GetInstance()->overlay_filter()->Deactivate(); |
| 68 views::Widget* widget = GetWidget(); |
| 69 if (widget) |
| 70 widget->Close(); |
| 71 } |
| 72 |
| 73 bool PartialScreenshotView::IsCancelingKeyEvent(aura::KeyEvent* event) { |
| 74 return event->key_code() == ui::VKEY_ESCAPE; |
| 75 } |
| 76 |
| 77 aura::Window* PartialScreenshotView::GetWindow() { |
| 78 return GetWidget()->GetNativeWindow(); |
| 79 } |
| 80 |
| 73 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { | 81 void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { |
| 74 if (is_dragging_) { | 82 if (is_dragging_) { |
| 75 // Screenshot area representation: black rectangle with white | 83 // Screenshot area representation: black rectangle with white |
| 76 // rectangle inside. To avoid capturing these rectangles when mouse | 84 // rectangle inside. To avoid capturing these rectangles when mouse |
| 77 // release, they should be outside of the actual capturing area. | 85 // release, they should be outside of the actual capturing area. |
| 78 gfx::Rect screenshot_rect = GetScreenshotRect(); | 86 gfx::Rect screenshot_rect = GetScreenshotRect(); |
| 79 screenshot_rect.Inset(-1, -1, -1, -1); | 87 screenshot_rect.Inset(-1, -1, -1, -1); |
| 80 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); | 88 canvas->DrawRect(screenshot_rect, SK_ColorWHITE); |
| 81 screenshot_rect.Inset(-1, -1, -1, -1); | 89 screenshot_rect.Inset(-1, -1, -1, -1); |
| 82 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); | 90 canvas->DrawRect(screenshot_rect, SK_ColorBLACK); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 127 |
| 120 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { | 128 gfx::Rect PartialScreenshotView::GetScreenshotRect() const { |
| 121 int left = std::min(start_position_.x(), current_position_.x()); | 129 int left = std::min(start_position_.x(), current_position_.x()); |
| 122 int top = std::min(start_position_.y(), current_position_.y()); | 130 int top = std::min(start_position_.y(), current_position_.y()); |
| 123 int width = ::abs(start_position_.x() - current_position_.x()); | 131 int width = ::abs(start_position_.x() - current_position_.x()); |
| 124 int height = ::abs(start_position_.y() - current_position_.y()); | 132 int height = ::abs(start_position_.y() - current_position_.y()); |
| 125 return gfx::Rect(left, top, width, height); | 133 return gfx::Rect(left, top, width, height); |
| 126 } | 134 } |
| 127 | 135 |
| 128 } // namespace ash | 136 } // namespace ash |
| OLD | NEW |