OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/shelf/shelf_layout_manager.h" |
| 6 #include "ash/shell.h" |
| 7 #include "ash/shell_window_ids.h" |
| 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 9 #include "chrome/browser/chromeos/accessibility/chromevox_panel.h" |
| 10 #include "chrome/common/extensions/extension_constants.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "ui/chromeos/accessibility_types.h" |
| 13 #include "ui/views/controls/webview/webview.h" |
| 14 #include "ui/views/layout/fill_layout.h" |
| 15 #include "ui/views/widget/widget.h" |
| 16 #include "ui/wm/core/shadow_types.h" |
| 17 #include "ui/wm/core/window_animations.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 const int kPanelHeight = 35; |
| 22 const char kChromeVoxPanelRelativeUrl[] = "/cvox2/background/panel.html"; |
| 23 const char kFullscreenURLFragment[] = "fullscreen"; |
| 24 const char kDisableSpokenFeedbackURLFragment[] = "close"; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 class ChromeVoxPanelWebContentsObserver : public content::WebContentsObserver { |
| 29 public: |
| 30 ChromeVoxPanelWebContentsObserver(content::WebContents* web_contents, |
| 31 ChromeVoxPanel* panel) |
| 32 : content::WebContentsObserver(web_contents), panel_(panel) {} |
| 33 ~ChromeVoxPanelWebContentsObserver() override {} |
| 34 |
| 35 // content::WebContentsObserver overrides. |
| 36 void DidFirstVisuallyNonEmptyPaint() override { |
| 37 panel_->DidFirstVisuallyNonEmptyPaint(); |
| 38 } |
| 39 |
| 40 void DidFinishNavigation( |
| 41 content::NavigationHandle* navigation_handle) override { |
| 42 // The ChromeVox panel uses the URL fragment to communicate state |
| 43 // to this panel host. |
| 44 std::string fragment = web_contents()->GetLastCommittedURL().ref(); |
| 45 if (fragment == kDisableSpokenFeedbackURLFragment) |
| 46 panel_->DisableSpokenFeedback(); |
| 47 else if (fragment == kFullscreenURLFragment) |
| 48 panel_->EnterFullscreen(); |
| 49 else |
| 50 panel_->ExitFullscreen(); |
| 51 } |
| 52 |
| 53 private: |
| 54 ChromeVoxPanel* panel_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebContentsObserver); |
| 57 }; |
| 58 |
| 59 ChromeVoxPanel::ChromeVoxPanel(content::BrowserContext* browser_context) |
| 60 : widget_(nullptr), web_view_(nullptr), fullscreen_(false) { |
| 61 std::string url("chrome-extension://"); |
| 62 url += extension_misc::kChromeVoxExtensionId; |
| 63 url += kChromeVoxPanelRelativeUrl; |
| 64 |
| 65 views::WebView* web_view = new views::WebView(browser_context); |
| 66 web_contents_observer_.reset( |
| 67 new ChromeVoxPanelWebContentsObserver(web_view->GetWebContents(), this)); |
| 68 web_view->LoadInitialURL(GURL(url)); |
| 69 web_view_ = web_view; |
| 70 |
| 71 widget_ = new views::Widget(); |
| 72 views::Widget::InitParams params( |
| 73 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 74 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 75 params.parent = ash::Shell::GetContainer( |
| 76 root_window, ash::kShellWindowId_SettingBubbleContainer); |
| 77 params.delegate = this; |
| 78 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 79 params.bounds = gfx::Rect(0, 0, root_window->bounds().width(), |
| 80 root_window->bounds().height()); |
| 81 widget_->Init(params); |
| 82 SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR); |
| 83 |
| 84 ash::Shell::GetScreen()->AddObserver(this); |
| 85 } |
| 86 |
| 87 ChromeVoxPanel::~ChromeVoxPanel() { |
| 88 ash::Shell::GetScreen()->RemoveObserver(this); |
| 89 } |
| 90 |
| 91 aura::Window* ChromeVoxPanel::GetRootWindow() { |
| 92 return GetWidget()->GetNativeWindow()->GetRootWindow(); |
| 93 } |
| 94 |
| 95 void ChromeVoxPanel::Close() { |
| 96 widget_->Close(); |
| 97 } |
| 98 |
| 99 void ChromeVoxPanel::DidFirstVisuallyNonEmptyPaint() { |
| 100 widget_->Show(); |
| 101 ash::ShelfLayoutManager::ForShelf(GetRootWindow()) |
| 102 ->SetChromeVoxPanelHeight(kPanelHeight); |
| 103 } |
| 104 |
| 105 void ChromeVoxPanel::EnterFullscreen() { |
| 106 fullscreen_ = true; |
| 107 UpdateWidgetBounds(); |
| 108 } |
| 109 |
| 110 void ChromeVoxPanel::ExitFullscreen() { |
| 111 fullscreen_ = false; |
| 112 UpdateWidgetBounds(); |
| 113 } |
| 114 |
| 115 void ChromeVoxPanel::DisableSpokenFeedback() { |
| 116 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback( |
| 117 false, ui::A11Y_NOTIFICATION_NONE); |
| 118 } |
| 119 |
| 120 const views::Widget* ChromeVoxPanel::GetWidget() const { |
| 121 return widget_; |
| 122 } |
| 123 |
| 124 views::Widget* ChromeVoxPanel::GetWidget() { |
| 125 return widget_; |
| 126 } |
| 127 |
| 128 void ChromeVoxPanel::DeleteDelegate() { |
| 129 delete this; |
| 130 } |
| 131 |
| 132 views::View* ChromeVoxPanel::GetContentsView() { |
| 133 return web_view_; |
| 134 } |
| 135 |
| 136 void ChromeVoxPanel::OnDisplayMetricsChanged(const gfx::Display& display, |
| 137 uint32_t changed_metrics) { |
| 138 UpdateWidgetBounds(); |
| 139 } |
| 140 |
| 141 void ChromeVoxPanel::UpdateWidgetBounds() { |
| 142 gfx::Rect bounds(GetRootWindow()->bounds().size()); |
| 143 if (!fullscreen_) |
| 144 bounds.set_height(kPanelHeight); |
| 145 widget_->SetBounds(bounds); |
| 146 } |
OLD | NEW |