Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Side by Side Diff: chrome/browser/chromeos/accessibility/chromevox_panel.cc

Issue 1274563004: Show ChromeVox caption panel when spoken feedback is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chromevox_panel_html
Patch Set: Add SetDisplayWorkAreaInsetsForTesting for tests Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/shell.h"
6 #include "ash/shell_window_ids.h"
7 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
8 #include "chrome/browser/chromeos/accessibility/chromevox_panel.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "content/public/browser/web_contents.h"
11 #include "ui/chromeos/accessibility_types.h"
12 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/layout/fill_layout.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/wm/core/shadow_types.h"
16 #include "ui/wm/core/window_animations.h"
17
18 namespace {
19
20 const int kPanelHeight = 35;
21 const char kChromeVoxPanelRelativeUrl[] = "/cvox2/background/panel.html";
22 const char kFullscreenURLFragment[] = "fullscreen";
23 const char kDisableSpokenFeedbackURLFragment[] = "close";
24
25 } // namespace
26
27 class ChromeVoxPanelWebContentsObserver : public content::WebContentsObserver {
28 public:
29 ChromeVoxPanelWebContentsObserver(content::WebContents* web_contents,
30 ChromeVoxPanel* panel)
31 : content::WebContentsObserver(web_contents), panel_(panel) {}
32 ~ChromeVoxPanelWebContentsObserver() override {}
33
34 // content::WebContentsObserver overrides.
35 void DidFirstVisuallyNonEmptyPaint() override {
36 panel_->DidFirstVisuallyNonEmptyPaint();
37 }
38
39 void DidFinishNavigation(
40 content::NavigationHandle* navigation_handle) override {
41 // The ChromeVox panel uses the URL fragment to communicate state
42 // to this panel host.
43 std::string fragment = web_contents()->GetLastCommittedURL().ref();
44 if (fragment == kDisableSpokenFeedbackURLFragment)
45 panel_->DisableSpokenFeedback();
46 else if (fragment == kFullscreenURLFragment)
47 panel_->EnterFullscreen();
48 else
49 panel_->ExitFullscreen();
50 }
51
52 private:
53 ChromeVoxPanel* panel_;
54
55 DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebContentsObserver);
56 };
57
58 ChromeVoxPanel::ChromeVoxPanel(content::BrowserContext* browser_context) {
59 std::string url("chrome-extension://");
60 url += extension_misc::kChromeVoxExtensionId;
61 url += kChromeVoxPanelRelativeUrl;
62
63 web_view_ = new views::WebView(browser_context);
64 web_contents_observer_.reset(
65 new ChromeVoxPanelWebContentsObserver(web_view_->GetWebContents(), this));
66 web_view_->LoadInitialURL(GURL(url));
67
68 widget_ = new views::Widget();
69 views::Widget::InitParams params(
70 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
71 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
72 params.parent = ash::Shell::GetContainer(
73 root_window, ash::kShellWindowId_SettingBubbleContainer);
74 params.delegate = this;
75 params.bounds = gfx::Rect(0, 0, root_window->bounds().width(),
76 root_window->bounds().height());
77 widget_->Init(params);
78 SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR);
79
80 ash::Shell::GetScreen()->AddObserver(this);
81 }
82
83 ChromeVoxPanel::~ChromeVoxPanel() {
84 ash::Shell::GetScreen()->RemoveObserver(this);
85 }
86
87 int ChromeVoxPanel::GetHeight() {
88 return kPanelHeight;
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::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(GetRootWindow());
102 }
103
104 void ChromeVoxPanel::EnterFullscreen() {
105 fullscreen_ = true;
106 UpdateWidgetBounds();
107 }
108
109 void ChromeVoxPanel::ExitFullscreen() {
110 fullscreen_ = false;
111 UpdateWidgetBounds();
112 }
113
114 void ChromeVoxPanel::DisableSpokenFeedback() {
115 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
116 false, ui::A11Y_NOTIFICATION_NONE);
117 }
118
119 const views::Widget* ChromeVoxPanel::GetWidget() const {
120 return widget_;
121 }
122
123 views::Widget* ChromeVoxPanel::GetWidget() {
124 return widget_;
125 }
126
127 void ChromeVoxPanel::DeleteDelegate() {
128 delete this;
129 }
130
131 views::View* ChromeVoxPanel::GetContentsView() {
132 return web_view_;
Jun Mukai 2015/11/06 18:21:04 You don't have to remember |web_view_| as an insta
dmazzoni 2015/11/09 23:02:06 Well, I need the BrowserContext to initialize the
133 }
134
135 void ChromeVoxPanel::OnDisplayMetricsChanged(const gfx::Display& display,
136 uint32_t changed_metrics) {
137 UpdateWidgetBounds();
138 ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(GetRootWindow());
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698