diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-08 14:30:41 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-12 13:49:54 +0200 |
commit | ab0a50979b9eb4dfa3320eff7e187e41efedf7a9 (patch) | |
tree | 498dfb8a97ff3361a9f7486863a52bb4e26bb898 /chromium/ash/keyboard_overlay | |
parent | 4ce69f7403811819800e7c5ae1318b2647e778d1 (diff) |
Update Chromium to beta version 37.0.2062.68
Change-Id: I188e3b5aff1bec75566014291b654eb19f5bc8ca
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'chromium/ash/keyboard_overlay')
6 files changed, 0 insertions, 524 deletions
diff --git a/chromium/ash/keyboard_overlay/keyboard_overlay_delegate.cc b/chromium/ash/keyboard_overlay/keyboard_overlay_delegate.cc deleted file mode 100644 index 5f0da86d50d..00000000000 --- a/chromium/ash/keyboard_overlay/keyboard_overlay_delegate.cc +++ /dev/null @@ -1,149 +0,0 @@ -// 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/keyboard_overlay/keyboard_overlay_delegate.h" - -#include <algorithm> - -#include "ash/shell.h" -#include "base/bind.h" -#include "base/memory/weak_ptr.h" -#include "base/strings/utf_string_conversions.h" -#include "base/values.h" -#include "content/public/browser/web_ui.h" -#include "content/public/browser/web_ui_message_handler.h" -#include "ui/aura/root_window.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/screen.h" -#include "ui/views/controls/webview/web_dialog_view.h" -#include "ui/views/widget/widget.h" - -using content::WebContents; -using content::WebUIMessageHandler; - -namespace { - -const int kBaseWidth = 1252; -const int kBaseHeight = 516; -const int kHorizontalMargin = 28; - -// A message handler for detecting the timing when the web contents is painted. -class PaintMessageHandler - : public WebUIMessageHandler, - public base::SupportsWeakPtr<PaintMessageHandler> { - public: - explicit PaintMessageHandler(views::Widget* widget) : widget_(widget) {} - virtual ~PaintMessageHandler() {} - - // WebUIMessageHandler implementation. - virtual void RegisterMessages() OVERRIDE; - - private: - void DidPaint(const ListValue* args); - - views::Widget* widget_; - - DISALLOW_COPY_AND_ASSIGN(PaintMessageHandler); -}; - -void PaintMessageHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback( - "didPaint", - base::Bind(&PaintMessageHandler::DidPaint, base::Unretained(this))); -} - -void PaintMessageHandler::DidPaint(const ListValue* args) { - // Show the widget after the web content has been painted. - widget_->Show(); -} - -} // namespace - -namespace ash { - -KeyboardOverlayDelegate::KeyboardOverlayDelegate(const base::string16& title, - const GURL& url) - : title_(title), - url_(url), - widget_(NULL) { -} - -KeyboardOverlayDelegate::~KeyboardOverlayDelegate() { -} - -views::Widget* KeyboardOverlayDelegate::Show(views::WebDialogView* view) { - widget_ = new views::Widget; - views::Widget::InitParams params( - views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.context = Shell::GetPrimaryRootWindow(); - params.delegate = view; - widget_->Init(params); - - // Show the widget at the bottom of the work area. - gfx::Size size; - GetDialogSize(&size); - const gfx::Rect& rect = Shell::GetScreen()->GetDisplayNearestWindow( - widget_->GetNativeView()).work_area(); - gfx::Rect bounds(rect.x() + (rect.width() - size.width()) / 2, - rect.bottom() - size.height(), - size.width(), - size.height()); - widget_->SetBounds(bounds); - - // The widget will be shown when the web contents gets ready to display. - return widget_; -} - -ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const { - return ui::MODAL_TYPE_SYSTEM; -} - -base::string16 KeyboardOverlayDelegate::GetDialogTitle() const { - return title_; -} - -GURL KeyboardOverlayDelegate::GetDialogContentURL() const { - return url_; -} - -void KeyboardOverlayDelegate::GetWebUIMessageHandlers( - std::vector<WebUIMessageHandler*>* handlers) const { - handlers->push_back(new PaintMessageHandler(widget_)); -} - -void KeyboardOverlayDelegate::GetDialogSize( - gfx::Size* size) const { - using std::min; - DCHECK(widget_); - gfx::Rect rect = ash::Shell::GetScreen()->GetDisplayNearestWindow( - widget_->GetNativeView()).work_area(); - const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); - const int height = width * kBaseHeight / kBaseWidth; - size->SetSize(width, height); -} - -std::string KeyboardOverlayDelegate::GetDialogArgs() const { - return "[]"; -} - -void KeyboardOverlayDelegate::OnDialogClosed( - const std::string& json_retval) { - delete this; - return; -} - -void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, - bool* out_close_dialog) { -} - -bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { - return false; -} - -bool KeyboardOverlayDelegate::HandleContextMenu( - const content::ContextMenuParams& params) { - return true; -} - -} // namespace ash diff --git a/chromium/ash/keyboard_overlay/keyboard_overlay_delegate.h b/chromium/ash/keyboard_overlay/keyboard_overlay_delegate.h deleted file mode 100644 index caf8f2a9cc4..00000000000 --- a/chromium/ash/keyboard_overlay/keyboard_overlay_delegate.h +++ /dev/null @@ -1,66 +0,0 @@ -// 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_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_ -#define ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/gtest_prod_util.h" -#include "ui/web_dialogs/web_dialog_delegate.h" -#include "url/gurl.h" - -namespace views { -class WebDialogView; -class Widget; -} - -namespace ash { - -// Delegate to handle showing the keyboard overlay drawing. Exported for test. -class ASH_EXPORT KeyboardOverlayDelegate : public ui::WebDialogDelegate { - public: - KeyboardOverlayDelegate(const base::string16& title, const GURL& url); - - // Shows the keyboard overlay widget. Returns the widget for testing. - views::Widget* Show(views::WebDialogView* view); - - // Overridden from ui::WebDialogDelegate: - virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; - - private: - FRIEND_TEST_ALL_PREFIXES(KeyboardOverlayDelegateTest, ShowAndClose); - - virtual ~KeyboardOverlayDelegate(); - - // Overridden from ui::WebDialogDelegate: - virtual ui::ModalType GetDialogModalType() const OVERRIDE; - virtual base::string16 GetDialogTitle() const OVERRIDE; - virtual GURL GetDialogContentURL() const OVERRIDE; - virtual void GetWebUIMessageHandlers( - std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE; - virtual std::string GetDialogArgs() const OVERRIDE; - virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; - virtual void OnCloseContents(content::WebContents* source, - bool* out_close_dialog) OVERRIDE; - virtual bool ShouldShowDialogTitle() const OVERRIDE; - virtual bool HandleContextMenu( - const content::ContextMenuParams& params) OVERRIDE; - - // The dialog title. - base::string16 title_; - - // The URL of the keyboard overlay. - GURL url_; - - // The widget associated with this delegate. Not owned. - views::Widget* widget_; - - DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayDelegate); -}; - -} // namespace ash - -#endif // ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_ diff --git a/chromium/ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc b/chromium/ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc deleted file mode 100644 index 95c048de7ac..00000000000 --- a/chromium/ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2013 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/keyboard_overlay/keyboard_overlay_delegate.h" - -#include "ash/shelf/shelf_types.h" -#include "ash/shell.h" -#include "ash/test/ash_test_base.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/window.h" -#include "ui/gfx/display.h" -#include "ui/gfx/screen.h" -#include "ui/views/widget/widget.h" - -namespace ash { - -class KeyboardOverlayDelegateTest - : public test::AshTestBase, - public testing::WithParamInterface<ShelfAlignment> { - public: - KeyboardOverlayDelegateTest() : shelf_alignment_(GetParam()) {} - virtual ~KeyboardOverlayDelegateTest() {} - ShelfAlignment shelf_alignment() const { return shelf_alignment_; } - - private: - ShelfAlignment shelf_alignment_; - - DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayDelegateTest); -}; - -// Verifies we can show and close the widget for the overlay dialog. -TEST_P(KeyboardOverlayDelegateTest, ShowAndClose) { - if (!SupportsMultipleDisplays()) - return; - - UpdateDisplay("500x400,300x200"); - ash::Shell* shell = ash::Shell::GetInstance(); - shell->SetShelfAlignment(shelf_alignment(), shell->GetPrimaryRootWindow()); - KeyboardOverlayDelegate delegate(ASCIIToUTF16("Title"), - GURL("chrome://keyboardoverlay/")); - // Showing the dialog creates a widget. - views::Widget* widget = delegate.Show(NULL); - EXPECT_TRUE(widget); - - // The widget is on the primary root window. - EXPECT_EQ(Shell::GetPrimaryRootWindow(), - widget->GetNativeWindow()->GetRootWindow()); - - // The widget is horizontally centered at the bottom of the work area. - gfx::Rect work_area = Shell::GetScreen()->GetPrimaryDisplay().work_area(); - gfx::Rect bounds = widget->GetRestoredBounds(); - EXPECT_EQ(work_area.CenterPoint().x(), bounds.CenterPoint().x()); - EXPECT_EQ(work_area.bottom(), bounds.bottom()); - - // Clean up. - widget->CloseNow(); -} - -// Tests run three times - for all possible values of shelf alignment -INSTANTIATE_TEST_CASE_P(ShelfAlignmentAny, - KeyboardOverlayDelegateTest, - testing::Values(SHELF_ALIGNMENT_BOTTOM, - SHELF_ALIGNMENT_LEFT, - SHELF_ALIGNMENT_RIGHT, - SHELF_ALIGNMENT_TOP)); - -} // namespace ash diff --git a/chromium/ash/keyboard_overlay/keyboard_overlay_view.cc b/chromium/ash/keyboard_overlay/keyboard_overlay_view.cc deleted file mode 100644 index 2847653ca57..00000000000 --- a/chromium/ash/keyboard_overlay/keyboard_overlay_view.cc +++ /dev/null @@ -1,95 +0,0 @@ -// 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/keyboard_overlay/keyboard_overlay_view.h" - -#include "ash/keyboard_overlay/keyboard_overlay_delegate.h" -#include "ash/shell.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/browser/browser_context.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/events/event.h" -#include "ui/gfx/screen.h" -#include "ui/views/widget/widget.h" -#include "ui/web_dialogs/web_dialog_delegate.h" - -using ui::WebDialogDelegate; - -namespace { - -// Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/, Help, F14). -const ash::KeyboardOverlayView::KeyEventData kCancelKeys[] = { - { ui::VKEY_ESCAPE, ui::EF_NONE}, - { ui::VKEY_OEM_2, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, - { ui::VKEY_OEM_2, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, - { ui::VKEY_HELP, ui::EF_NONE }, - { ui::VKEY_F14, ui::EF_NONE }, -}; - -} - -namespace ash { - -KeyboardOverlayView::KeyboardOverlayView( - content::BrowserContext* context, - WebDialogDelegate* delegate, - WebContentsHandler* handler) - : views::WebDialogView(context, delegate, handler) { -} - -KeyboardOverlayView::~KeyboardOverlayView() { -} - -void KeyboardOverlayView::Cancel() { - Shell::GetInstance()->overlay_filter()->Deactivate(); - views::Widget* widget = GetWidget(); - if (widget) - widget->Close(); -} - -bool KeyboardOverlayView::IsCancelingKeyEvent(ui::KeyEvent* event) { - if (event->type() != ui::ET_KEY_PRESSED) - return false; - // Ignore the caps lock state. - const int flags = (event->flags() & ~ui::EF_CAPS_LOCK_DOWN); - for (size_t i = 0; i < arraysize(kCancelKeys); ++i) { - if ((kCancelKeys[i].key_code == event->key_code()) && - (kCancelKeys[i].flags == flags)) - return true; - } - return false; -} - -aura::Window* KeyboardOverlayView::GetWindow() { - return GetWidget()->GetNativeWindow(); -} - -void KeyboardOverlayView::ShowDialog( - content::BrowserContext* context, - WebContentsHandler* handler, - const GURL& url) { - KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( - l10n_util::GetStringUTF16(IDS_ASH_KEYBOARD_OVERLAY_TITLE), url); - KeyboardOverlayView* view = - new KeyboardOverlayView(context, delegate, handler); - delegate->Show(view); - - Shell::GetInstance()->overlay_filter()->Activate(view); -} - -void KeyboardOverlayView::WindowClosing() { - Cancel(); -} - -// static -void KeyboardOverlayView::GetCancelingKeysForTesting( - std::vector<KeyboardOverlayView::KeyEventData>* canceling_keys) { - CHECK(canceling_keys); - canceling_keys->clear(); - for (size_t i = 0; i < arraysize(kCancelKeys); ++i) - canceling_keys->push_back(kCancelKeys[i]); -} - -} // namespace ash diff --git a/chromium/ash/keyboard_overlay/keyboard_overlay_view.h b/chromium/ash/keyboard_overlay/keyboard_overlay_view.h deleted file mode 100644 index 3e352ae3169..00000000000 --- a/chromium/ash/keyboard_overlay/keyboard_overlay_view.h +++ /dev/null @@ -1,68 +0,0 @@ -// 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_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_VIEW_H_ -#define ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_VIEW_H_ - -#include <vector> - -#include "ash/ash_export.h" -#include "ash/wm/overlay_event_filter.h" -#include "base/compiler_specific.h" -#include "base/gtest_prod_util.h" -#include "ui/views/controls/webview/web_dialog_view.h" - -class GURL; - -namespace content { -class BrowserContext; -} - -namespace ui { -class WebDialogDelegate; -} - -namespace ash { - -// A customized dialog view for the keyboard overlay. -class ASH_EXPORT KeyboardOverlayView - : public views::WebDialogView, - public ash::internal::OverlayEventFilter::Delegate { - public: - struct KeyEventData { - ui::KeyboardCode key_code; - int flags; - }; - - KeyboardOverlayView(content::BrowserContext* context, - ui::WebDialogDelegate* delegate, - WebContentsHandler* handler); - virtual ~KeyboardOverlayView(); - - // Overridden from ash::internal::OverlayEventFilter::Delegate: - virtual void Cancel() OVERRIDE; - virtual bool IsCancelingKeyEvent(ui::KeyEvent* event) OVERRIDE; - virtual aura::Window* GetWindow() OVERRIDE; - - // Shows the keyboard overlay. - static void ShowDialog(content::BrowserContext* context, - WebContentsHandler* handler, - const GURL& url); - - private: - FRIEND_TEST_ALL_PREFIXES(KeyboardOverlayViewTest, OpenAcceleratorsClose); - FRIEND_TEST_ALL_PREFIXES(KeyboardOverlayViewTest, NoRedundantCancelingKeys); - - // Overridden from views::WidgetDelegate: - virtual void WindowClosing() OVERRIDE; - - static void GetCancelingKeysForTesting( - std::vector<KeyEventData>* canceling_keys); - - DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayView); -}; - -} // namespace ash - -#endif // ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_VIEW_H_ diff --git a/chromium/ash/keyboard_overlay/keyboard_overlay_view_unittest.cc b/chromium/ash/keyboard_overlay/keyboard_overlay_view_unittest.cc deleted file mode 100644 index 8875f0ee75e..00000000000 --- a/chromium/ash/keyboard_overlay/keyboard_overlay_view_unittest.cc +++ /dev/null @@ -1,78 +0,0 @@ -// 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/keyboard_overlay/keyboard_overlay_view.h" - -#include <algorithm> - -#include "ash/accelerators/accelerator_table.h" -#include "ash/keyboard_overlay/keyboard_overlay_delegate.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/test/ash_test_base.h" -#include "ui/web_dialogs/test/test_web_contents_handler.h" -#include "ui/web_dialogs/test/test_web_dialog_delegate.h" - -namespace ash { - -typedef test::AshTestBase KeyboardOverlayViewTest; - -bool operator==(const KeyboardOverlayView::KeyEventData& lhs, - const KeyboardOverlayView::KeyEventData& rhs) { - return (lhs.key_code == rhs.key_code) && (lhs.flags == rhs.flags); -} - -// Verifies that the accelerators that open the keyboard overlay close it. -TEST_F(KeyboardOverlayViewTest, OpenAcceleratorsClose) { - ui::test::TestWebDialogDelegate delegate(GURL("chrome://keyboardoverlay")); - KeyboardOverlayView view( - Shell::GetInstance()->delegate()->GetActiveBrowserContext(), - &delegate, - new ui::test::TestWebContentsHandler); - for (size_t i = 0; i < kAcceleratorDataLength; ++i) { - if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY) - continue; - const AcceleratorData& open_key_data = kAcceleratorData[i]; - ui::KeyEvent open_key(open_key_data.trigger_on_press ? - ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, - open_key_data.keycode, - open_key_data.modifiers, - false); - EXPECT_TRUE(view.IsCancelingKeyEvent(&open_key)); - } -} - -// Verifies that there are no redunduant keys in the canceling keys. -TEST_F(KeyboardOverlayViewTest, NoRedundantCancelingKeys) { - std::vector<KeyboardOverlayView::KeyEventData> open_keys; - for (size_t i = 0; i < kAcceleratorDataLength; ++i) { - if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY) - continue; - // Escape is used just for canceling. - KeyboardOverlayView::KeyEventData open_key = { - kAcceleratorData[i].keycode, - kAcceleratorData[i].modifiers, - }; - open_keys.push_back(open_key); - } - - std::vector<KeyboardOverlayView::KeyEventData> canceling_keys; - KeyboardOverlayView::GetCancelingKeysForTesting(&canceling_keys); - - // Escape is used just for canceling, so exclude it from the comparison with - // open keys. - KeyboardOverlayView::KeyEventData escape = { ui::VKEY_ESCAPE, ui::EF_NONE }; - std::vector<KeyboardOverlayView::KeyEventData>::iterator escape_itr = - std::find(canceling_keys.begin(), canceling_keys.end(), escape); - canceling_keys.erase(escape_itr); - - // Other canceling keys should be same as opening keys. - EXPECT_EQ(open_keys.size(), canceling_keys.size()); - for (size_t i = 0; i < canceling_keys.size(); ++i) { - EXPECT_NE(std::find(open_keys.begin(), open_keys.end(), canceling_keys[i]), - open_keys.end()); - } -} - -} // namespace ash |