diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-16 13:23:45 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-16 13:23:45 +0000 |
commit | 0b0b074f6a864e98ad8bf7f78a583df86039e6e3 (patch) | |
tree | 92be984e5aac798ff2c063db90c73c0155e64a7f | |
parent | 5c1eeb8382a3ad697d90857ae3f7baf34a206bf7 (diff) | |
download | chromium_src-0b0b074f6a864e98ad8bf7f78a583df86039e6e3.zip chromium_src-0b0b074f6a864e98ad8bf7f78a583df86039e6e3.tar.gz chromium_src-0b0b074f6a864e98ad8bf7f78a583df86039e6e3.tar.bz2 |
Implement taking partial screenshot.
BUG=108763
TEST=manually && aura_shell_unittests passed
Review URL: http://codereview.chromium.org/9368051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122281 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 5 | ||||
-rw-r--r-- | ash/accelerators/accelerator_controller_unittest.cc | 24 | ||||
-rw-r--r-- | ash/ash.gyp | 4 | ||||
-rw-r--r-- | ash/shell.cc | 16 | ||||
-rw-r--r-- | ash/shell.h | 8 | ||||
-rw-r--r-- | ash/shell/shell_main.cc | 6 | ||||
-rw-r--r-- | ash/shell_delegate.h | 5 | ||||
-rw-r--r-- | ash/shell_unittest.cc | 2 | ||||
-rw-r--r-- | ash/shell_window_ids.h | 4 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.cc | 7 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.h | 2 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_event_filter.cc | 57 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_event_filter.h | 56 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_view.cc | 123 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_view.h | 57 | ||||
-rw-r--r-- | ash/wm/power_button_controller.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/aura/chrome_shell_delegate.cc | 7 | ||||
-rw-r--r-- | chrome/browser/ui/views/aura/chrome_shell_delegate.h | 2 |
18 files changed, 375 insertions, 11 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index e6e0764..5b0f42c 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -286,8 +286,9 @@ bool AcceleratorController::AcceleratorPressed( // Return true to prevent propagation of the key event. return true; case TAKE_PARTIAL_SCREENSHOT: - // TODO(mukai): implement this. http://crbug.com/108763 - NOTIMPLEMENTED(); + if (screenshot_delegate_.get()) + ash::Shell::GetInstance()->delegate()-> + StartPartialScreenshot(screenshot_delegate_.get()); // Return true to prevent propagation of the key event because // this key combination is reserved for partial screenshot. return true; diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc index 848fa44..b5f304a 100644 --- a/ash/accelerators/accelerator_controller_unittest.cc +++ b/ash/accelerators/accelerator_controller_unittest.cc @@ -53,7 +53,9 @@ class TestTarget : public ui::AcceleratorTarget { class DummyScreenshotDelegate : public ScreenshotDelegate { public: - DummyScreenshotDelegate() : handle_take_screenshot_count_(0) { + DummyScreenshotDelegate() + : handle_take_screenshot_count_(0), + handle_take_partial_screenshot_count_(0) { } virtual ~DummyScreenshotDelegate() {} @@ -65,15 +67,20 @@ class DummyScreenshotDelegate : public ScreenshotDelegate { virtual void HandleTakePartialScreenshot( aura::Window* window, const gfx::Rect& rect) OVERRIDE { - // Do nothing because it's not tested yet. + ++handle_take_partial_screenshot_count_; } int handle_take_screenshot_count() const { return handle_take_screenshot_count_; } + int handle_take_partial_screenshot_count() const { + return handle_take_partial_screenshot_count_; + } + private: int handle_take_screenshot_count_; + int handle_take_partial_screenshot_count_; DISALLOW_COPY_AND_ASSIGN(DummyScreenshotDelegate); }; @@ -346,29 +353,32 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) { ui::Accelerator(ui::VKEY_F5, false, false, false))); EXPECT_TRUE(GetController()->Process( ui::Accelerator(ui::VKEY_TAB, false, false, true))); - // TakeScreenshot + // Take screenshot / partial screenshot // True should always be returned regardless of the existence of the delegate. { EXPECT_TRUE(GetController()->Process( ui::Accelerator(ui::VKEY_F5, false, true, false))); EXPECT_TRUE(GetController()->Process( ui::Accelerator(ui::VKEY_PRINT, false, false, false))); + EXPECT_TRUE(GetController()->Process( + ui::Accelerator(ui::VKEY_F5, true, true, false))); DummyScreenshotDelegate* delegate = new DummyScreenshotDelegate; GetController()->SetScreenshotDelegate( scoped_ptr<ScreenshotDelegate>(delegate).Pass()); EXPECT_EQ(0, delegate->handle_take_screenshot_count()); + EXPECT_EQ(0, delegate->handle_take_partial_screenshot_count()); EXPECT_TRUE(GetController()->Process( ui::Accelerator(ui::VKEY_F5, false, true, false))); EXPECT_EQ(1, delegate->handle_take_screenshot_count()); + EXPECT_EQ(0, delegate->handle_take_partial_screenshot_count()); EXPECT_TRUE(GetController()->Process( ui::Accelerator(ui::VKEY_PRINT, false, false, false))); EXPECT_EQ(2, delegate->handle_take_screenshot_count()); - } - // TakePartialScreenshot - // So far, we just want to make sure the keybind is trapped here. - { + EXPECT_EQ(0, delegate->handle_take_partial_screenshot_count()); EXPECT_TRUE(GetController()->Process( ui::Accelerator(ui::VKEY_F5, true, true, false))); + EXPECT_EQ(2, delegate->handle_take_screenshot_count()); + EXPECT_EQ(1, delegate->handle_take_partial_screenshot_count()); } // ToggleCapsLock { diff --git a/ash/ash.gyp b/ash/ash.gyp index 2202d08..63cf478 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -131,6 +131,10 @@ 'wm/panel_frame_view.h', 'wm/panel_layout_manager.cc', 'wm/panel_layout_manager.h', + 'wm/partial_screenshot_event_filter.cc', + 'wm/partial_screenshot_event_filter.h', + 'wm/partial_screenshot_view.cc', + 'wm/partial_screenshot_view.h', 'wm/system_modal_container_layout_manager.cc', 'wm/system_modal_container_layout_manager.h', 'wm/system_modal_container_event_filter.cc', diff --git a/ash/shell.cc b/ash/shell.cc index 7c3e6c2..b2f63fa 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -22,6 +22,7 @@ #include "ash/wm/compact_status_area_layout_manager.h" #include "ash/wm/dialog_frame_view.h" #include "ash/wm/panel_layout_manager.h" +#include "ash/wm/partial_screenshot_event_filter.h" #include "ash/wm/power_button_controller.h" #include "ash/wm/root_window_event_filter.h" #include "ash/wm/root_window_layout_manager.h" @@ -167,6 +168,10 @@ void CreateSpecialContainers(aura::Window::Windows* containers) { setting_bubble_container->set_id( internal::kShellWindowId_SettingBubbleContainer); containers->push_back(setting_bubble_container); + + aura::Window* overlay_container = new aura::Window(NULL); + overlay_container->set_id(internal::kShellWindowId_OverlayContainer); + containers->push_back(overlay_container); } // Maximizes all the windows in a |container|. @@ -215,6 +220,7 @@ Shell::Shell(ShellDelegate* delegate) } Shell::~Shell() { + RemoveRootWindowEventFilter(partial_screenshot_filter_.get()); RemoveRootWindowEventFilter(input_method_filter_.get()); RemoveRootWindowEventFilter(window_modality_controller_.get()); #if !defined(OS_MACOSX) @@ -278,9 +284,15 @@ void Shell::DeleteInstance() { } void Shell::Init() { - // InputMethodEventFilter must be added first since it has the highest - // priority. DCHECK(!GetRootWindowEventFilterCount()); + + // PartialScreenshotEventFilter must be the first one to capture key + // events when the taking partial screenshot UI is there. + partial_screenshot_filter_.reset(new internal::PartialScreenshotEventFilter); + AddRootWindowEventFilter(partial_screenshot_filter_.get()); + + // InputMethodEventFilter must be added next to PartialScreenshot + // since it has the higher priority. input_method_filter_.reset(new internal::InputMethodEventFilter); AddRootWindowEventFilter(input_method_filter_.get()); diff --git a/ash/shell.h b/ash/shell.h index ca21b9f..25b98b2 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -50,6 +50,7 @@ class AppList; class DragDropController; class FocusCycler; class InputMethodEventFilter; +class PartialScreenshotEventFilter; class RootWindowEventFilter; class RootWindowLayoutManager; class ShadowController; @@ -155,6 +156,9 @@ class ASH_EXPORT Shell { internal::TooltipController* tooltip_controller() { return tooltip_controller_.get(); } + internal::PartialScreenshotEventFilter* partial_screenshot_filter() { + return partial_screenshot_filter_.get(); + } PowerButtonController* power_button_controller() { return power_button_controller_.get(); } @@ -237,6 +241,10 @@ class ASH_EXPORT Shell { // An event filter that pre-handles all key events to send them to an IME. scoped_ptr<internal::InputMethodEventFilter> input_method_filter_; + // An event filter that pre-handles key events while the partial + // screenshot UI is active. + scoped_ptr<internal::PartialScreenshotEventFilter> partial_screenshot_filter_; + #if !defined(OS_MACOSX) // An event filter that pre-handles global accelerators. scoped_ptr<internal::AcceleratorFilter> accelerator_filter_; diff --git a/ash/shell/shell_main.cc b/ash/shell/shell_main.cc index 4dc19b3..7b50104 100644 --- a/ash/shell/shell_main.cc +++ b/ash/shell/shell_main.cc @@ -15,6 +15,7 @@ #include "ash/shell/example_factory.h" #include "ash/shell/shell_main_parts.h" #include "ash/shell/toplevel_window.h" +#include "ash/wm/partial_screenshot_view.h" #include "ash/wm/window_util.h" #include "base/at_exit.h" #include "base/command_line.h" @@ -185,6 +186,11 @@ class ShellDelegateImpl : public ash::ShellDelegate { return windows; } + virtual void StartPartialScreenshot( + ash::ScreenshotDelegate* screenshot_delegate) OVERRIDE { + ash::PartialScreenshotView::StartPartialScreenshot(screenshot_delegate); + } + virtual ash::LauncherDelegate* CreateLauncherDelegate() OVERRIDE { return new LauncherDelegateImpl(watcher_); } diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index f268346..8e696da 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -26,6 +26,7 @@ class AppListModel; class AppListViewDelegate; class LauncherDelegate; struct LauncherItem; +class ScreenshotDelegate; // Delegate of the Shell. class ASH_EXPORT ShellDelegate { @@ -74,6 +75,10 @@ class ASH_EXPORT ShellDelegate { CycleSource source, CycleOrder order) const = 0; + // Invoked to start taking partial screenshot. + virtual void StartPartialScreenshot( + ScreenshotDelegate* screenshot_delegate) = 0; + // Creates a new LauncherDelegate. Shell takes ownership of the returned // value. virtual LauncherDelegate* CreateLauncherDelegate() = 0; diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc index a49f27dd..9782fbd 100644 --- a/ash/shell_unittest.cc +++ b/ash/shell_unittest.cc @@ -68,6 +68,8 @@ void ExpectAllContainers() { internal::kShellWindowId_DragImageAndTooltipContainer)); EXPECT_TRUE( shell->GetContainer(internal::kShellWindowId_SettingBubbleContainer)); + EXPECT_TRUE( + shell->GetContainer(internal::kShellWindowId_OverlayContainer)); } void TestCreateWindow(views::Widget::InitParams::Type type, diff --git a/ash/shell_window_ids.h b/ash/shell_window_ids.h index 981698f..ff5d441 100644 --- a/ash/shell_window_ids.h +++ b/ash/shell_window_ids.h @@ -53,6 +53,10 @@ const int kShellWindowId_DragImageAndTooltipContainer = 11; // (volume, brightness, etc.). const int kShellWindowId_SettingBubbleContainer = 12; +// The container for special components overlaid onscreen, such as the +// region selector for partial screenshots. +const int kShellWindowId_OverlayContainer = 13; + } // namespace internal } // namespace ash diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index c78cc20..648936f 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "ash/screenshot_delegate.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "grit/ui_resources.h" @@ -54,6 +55,12 @@ std::vector<aura::Window*> TestShellDelegate::GetCycleWindowList( return windows; } +void TestShellDelegate::StartPartialScreenshot( + ScreenshotDelegate* screenshot_delegate) { + if (screenshot_delegate) + screenshot_delegate->HandleTakePartialScreenshot(NULL, gfx::Rect()); +} + LauncherDelegate* TestShellDelegate::CreateLauncherDelegate() { return NULL; } diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index 8474be1..5410115 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -28,6 +28,8 @@ class TestShellDelegate : public ShellDelegate { virtual std::vector<aura::Window*> GetCycleWindowList( CycleSource source, CycleOrder order) const OVERRIDE; + virtual void StartPartialScreenshot( + ScreenshotDelegate* screenshot_delegate) OVERRIDE; virtual LauncherDelegate* CreateLauncherDelegate() OVERRIDE; }; diff --git a/ash/wm/partial_screenshot_event_filter.cc b/ash/wm/partial_screenshot_event_filter.cc new file mode 100644 index 0000000..c3632e9 --- /dev/null +++ b/ash/wm/partial_screenshot_event_filter.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/wm/partial_screenshot_event_filter.h" + +#include "ash/wm/partial_screenshot_view.h" + +namespace ash { +namespace internal { + +PartialScreenshotEventFilter::PartialScreenshotEventFilter() + : view_(NULL) { +} + +PartialScreenshotEventFilter::~PartialScreenshotEventFilter() { + view_ = NULL; +} + +bool PartialScreenshotEventFilter::PreHandleKeyEvent( + aura::Window* target, aura::KeyEvent* event) { + if (!view_) + return false; + + if (event->key_code() == ui::VKEY_ESCAPE) + view_->Cancel(); + + // Always handled: other windows shouldn't receive input while we're + // taking a screenshot. + return true; +} + +bool PartialScreenshotEventFilter::PreHandleMouseEvent( + aura::Window* target, aura::MouseEvent* event) { + return false; // Not handled. +} + +ui::TouchStatus PartialScreenshotEventFilter::PreHandleTouchEvent( + aura::Window* target, aura::TouchEvent* event) { + return ui::TOUCH_STATUS_UNKNOWN; // Not handled. +} + +ui::GestureStatus PartialScreenshotEventFilter::PreHandleGestureEvent( + aura::Window* target, aura::GestureEvent* event) { + return ui::GESTURE_STATUS_UNKNOWN; // Not handled. +} + +void PartialScreenshotEventFilter::Activate(PartialScreenshotView* view) { + view_ = view; +} + +void PartialScreenshotEventFilter::Deactivate() { + view_ = NULL; +} + +} // namespace internal +} // namespace ash diff --git a/ash/wm/partial_screenshot_event_filter.h b/ash/wm/partial_screenshot_event_filter.h new file mode 100644 index 0000000..5f045de --- /dev/null +++ b/ash/wm/partial_screenshot_event_filter.h @@ -0,0 +1,56 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_WM_PARTIAL_SCREENSHOT_EVENT_FILTER_H_ +#define ASH_WM_PARTIAL_SCREENSHOT_EVENT_FILTER_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "ui/aura/event.h" +#include "ui/aura/event_filter.h" + +namespace ash { +class PartialScreenshotView; + +namespace internal { + +// EventFilter for the partial screenshot UI. It does nothing +// for the first time, but works when |Activate()| is called. The +// main task of this event filter is just to stop propagation of any +// key events during activation, and also signal cancellation when Esc is +// pressed. +class PartialScreenshotEventFilter : public aura::EventFilter { + public: + PartialScreenshotEventFilter(); + virtual ~PartialScreenshotEventFilter(); + + // Start the filtering of events. It also notifies the specified + // |view| when a key event means cancel (like Esc). It holds the + // pointer to the specified |view| until Deactivate() is called, but + // does not take ownership. + void Activate(PartialScreenshotView* view); + + // End the filtering of events. + void Deactivate(); + + // Overridden from aura::EventFilter: + virtual bool PreHandleKeyEvent( + aura::Window* target, aura::KeyEvent* event) OVERRIDE; + virtual bool PreHandleMouseEvent( + aura::Window* target, aura::MouseEvent* event) OVERRIDE; + virtual ui::TouchStatus PreHandleTouchEvent( + aura::Window* target, aura::TouchEvent* event) OVERRIDE; + virtual ui::GestureStatus PreHandleGestureEvent( + aura::Window* target, aura::GestureEvent* event) OVERRIDE; + + private: + PartialScreenshotView* view_; + + DISALLOW_COPY_AND_ASSIGN(PartialScreenshotEventFilter); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_WM_PARTIAL_SCREENSHOT_EVENT_FILTER_H_ diff --git a/ash/wm/partial_screenshot_view.cc b/ash/wm/partial_screenshot_view.cc new file mode 100644 index 0000000..bb83c5e --- /dev/null +++ b/ash/wm/partial_screenshot_view.cc @@ -0,0 +1,123 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/wm/partial_screenshot_view.h" + +#include "ash/screenshot_delegate.h" +#include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/wm/partial_screenshot_event_filter.h" +#include "ui/aura/cursor.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/rect.h" +#include "ui/views/view.h" +#include "ui/views/widget/widget.h" + +namespace ash { + +PartialScreenshotView::PartialScreenshotView( + ScreenshotDelegate* screenshot_delegate) + : is_dragging_(false), + screenshot_delegate_(screenshot_delegate), + window_(NULL) { +} + +PartialScreenshotView::~PartialScreenshotView() { + screenshot_delegate_ = NULL; + // Do not delete the |window_| here because |window_| has the + // ownership to this object. In case that finishing browser happens + // while |window_| != NULL, |window_| is still removed correctly by + // its parent container. + window_ = NULL; +} + +// static +void PartialScreenshotView::StartPartialScreenshot( + ScreenshotDelegate* screenshot_delegate) { + views::Widget* widget = new views::Widget; + PartialScreenshotView* view = new PartialScreenshotView( + screenshot_delegate); + + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.transparent = true; + params.delegate = view; + // The partial screenshot rectangle has to be at the real top of + // the screen. + params.parent = Shell::GetInstance()->GetContainer( + internal::kShellWindowId_OverlayContainer); + + widget->Init(params); + widget->SetContentsView(view); + widget->SetBounds(aura::RootWindow::GetInstance()->bounds()); + widget->GetNativeView()->SetName("PartialScreenshotView"); + widget->StackAtTop(); + widget->Show(); + + view->set_window(widget->GetNativeWindow()); + Shell::GetInstance()->partial_screenshot_filter()->Activate(view); +} + +void PartialScreenshotView::Cancel() { + DCHECK(window_); + window_->Hide(); + Shell::GetInstance()->partial_screenshot_filter()->Deactivate(); + MessageLoop::current()->DeleteSoon(FROM_HERE, window_); +} + +gfx::NativeCursor PartialScreenshotView::GetCursor( + const views::MouseEvent& event) { + // Always use "crosshair" cursor. + return aura::kCursorCross; +} + +void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) { + if (is_dragging_) { + // Screenshot area representation: black rectangle with white + // rectangle inside. + gfx::Rect screenshot_rect = GetScreenshotRect(); + canvas->DrawRect(screenshot_rect, SK_ColorBLACK); + screenshot_rect.Inset(1, 1, 1, 1); + canvas->DrawRect(screenshot_rect, SK_ColorWHITE); + } +} + +bool PartialScreenshotView::OnMousePressed(const views::MouseEvent& event) { + start_position_ = event.location(); + is_dragging_ = true; + return true; +} + +bool PartialScreenshotView::OnMouseDragged(const views::MouseEvent& event) { + current_position_ = event.location(); + SchedulePaint(); + return true; +} + +bool PartialScreenshotView::OnMouseWheel(const views::MouseWheelEvent& event) { + // Do nothing but do not propagate events futhermore. + return true; +} + +void PartialScreenshotView::OnMouseReleased(const views::MouseEvent& event) { + is_dragging_ = false; + Cancel(); + if (screenshot_delegate_) { + aura::RootWindow *root_window = aura::RootWindow::GetInstance(); + screenshot_delegate_->HandleTakePartialScreenshot( + root_window, root_window->bounds().Intersect(GetScreenshotRect())); + } +} + +gfx::Rect PartialScreenshotView::GetScreenshotRect() const { + int left = std::min(start_position_.x(), current_position_.x()); + int top = std::min(start_position_.y(), current_position_.y()); + int width = ::abs(start_position_.x() - current_position_.x()); + int height = ::abs(start_position_.y() - current_position_.y()); + return gfx::Rect(left, top, width, height); +} + +} // namespace ash diff --git a/ash/wm/partial_screenshot_view.h b/ash/wm/partial_screenshot_view.h new file mode 100644 index 0000000..8e666f3 --- /dev/null +++ b/ash/wm/partial_screenshot_view.h @@ -0,0 +1,57 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ +#define ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/compiler_specific.h" +#include "ui/gfx/point.h" +#include "ui/views/widget/widget_delegate.h" + +namespace ash { +class ScreenshotDelegate; + +// The view of taking partial screenshot, i.e.: drawing region +// rectangles during drag, and changing the mouse cursor to indicate +// the current mode. +class ASH_EXPORT PartialScreenshotView : public views::WidgetDelegateView { + public: + PartialScreenshotView(ScreenshotDelegate* screenshot_delegate); + virtual ~PartialScreenshotView(); + + // Starts the UI for taking partial screenshot; dragging to select a region. + static void StartPartialScreenshot(ScreenshotDelegate* screenshot_delegate); + + // Cancels the current screenshot UI. + void Cancel(); + + // Overriddden from View: + virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE; + + private: + gfx::Rect GetScreenshotRect() const; + + void set_window(aura::Window* window) { window_ = window; } + + // Overridden from View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; + virtual bool OnMouseWheel(const views::MouseWheelEvent& event) OVERRIDE; + virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; + + bool is_dragging_; + gfx::Point start_position_; + gfx::Point current_position_; + ScreenshotDelegate* screenshot_delegate_; + aura::Window* window_; + + DISALLOW_COPY_AND_ASSIGN(PartialScreenshotView); +}; + +} // namespace ash + +#endif // #ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc index 5263e02..236a9d3 100644 --- a/ash/wm/power_button_controller.cc +++ b/ash/wm/power_button_controller.cc @@ -77,6 +77,7 @@ const int kRelatedContainerIds[] = { internal::kShellWindowId_MenuContainer, internal::kShellWindowId_DragImageAndTooltipContainer, internal::kShellWindowId_SettingBubbleContainer, + internal::kShellWindowId_OverlayContainer, }; // Is |window| a container that holds screen locker windows? diff --git a/chrome/browser/ui/views/aura/chrome_shell_delegate.cc b/chrome/browser/ui/views/aura/chrome_shell_delegate.cc index bb1ee5e..60aef20 100644 --- a/chrome/browser/ui/views/aura/chrome_shell_delegate.cc +++ b/chrome/browser/ui/views/aura/chrome_shell_delegate.cc @@ -4,6 +4,8 @@ #include "chrome/browser/ui/views/aura/chrome_shell_delegate.h" +#include "ash/launcher/launcher_types.h" +#include "ash/wm/partial_screenshot_view.h" #include "ash/wm/window_util.h" #include "base/command_line.h" #include "chrome/browser/profiles/profile_manager.h" @@ -110,6 +112,11 @@ std::vector<aura::Window*> ChromeShellDelegate::GetCycleWindowList( return windows; } +void ChromeShellDelegate::StartPartialScreenshot( + ash::ScreenshotDelegate* screenshot_delegate) { + ash::PartialScreenshotView::StartPartialScreenshot(screenshot_delegate); +} + ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate() { return new ChromeLauncherDelegate; } diff --git a/chrome/browser/ui/views/aura/chrome_shell_delegate.h b/chrome/browser/ui/views/aura/chrome_shell_delegate.h index 386c6ee..ea8c37b 100644 --- a/chrome/browser/ui/views/aura/chrome_shell_delegate.h +++ b/chrome/browser/ui/views/aura/chrome_shell_delegate.h @@ -43,6 +43,8 @@ class ChromeShellDelegate : public ash::ShellDelegate { virtual std::vector<aura::Window*> GetCycleWindowList( CycleSource source, CycleOrder order) const OVERRIDE; + virtual void StartPartialScreenshot( + ash::ScreenshotDelegate* screenshot_delegate) OVERRIDE; virtual ash::LauncherDelegate* CreateLauncherDelegate() OVERRIDE; private: |