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

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: Keep responsibility for insets in ShelfLayoutManager 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/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) {
oshima 2015/11/10 19:47:51 initialize fullscreen_. I'd initialize widget_/web
dmazzoni 2015/11/10 21:55:51 Done.
60 std::string url("chrome-extension://");
61 url += extension_misc::kChromeVoxExtensionId;
62 url += kChromeVoxPanelRelativeUrl;
63
64 views::WebView* web_view = new views::WebView(browser_context);
65 web_contents_observer_.reset(
66 new ChromeVoxPanelWebContentsObserver(web_view->GetWebContents(), this));
67 web_view->LoadInitialURL(GURL(url));
68 web_view_ = web_view;
69
70 widget_ = new views::Widget();
71 views::Widget::InitParams params(
72 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
73 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
74 params.parent = ash::Shell::GetContainer(
75 root_window, ash::kShellWindowId_SettingBubbleContainer);
76 params.delegate = this;
77 params.bounds = gfx::Rect(0, 0, root_window->bounds().width(),
78 root_window->bounds().height());
79 widget_->Init(params);
80 SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR);
81
82 ash::Shell::GetScreen()->AddObserver(this);
83 }
84
85 ChromeVoxPanel::~ChromeVoxPanel() {
86 ash::Shell::GetScreen()->RemoveObserver(this);
87 }
88
89 aura::Window* ChromeVoxPanel::GetRootWindow() {
90 return GetWidget()->GetNativeWindow()->GetRootWindow();
91 }
92
93 void ChromeVoxPanel::Close() {
94 widget_->Close();
95 }
96
97 void ChromeVoxPanel::DidFirstVisuallyNonEmptyPaint() {
98 widget_->Show();
99 ash::ShelfLayoutManager::ForShelf(GetRootWindow())
100 ->SetChromeVoxPanelHeight(kPanelHeight);
101 }
102
103 void ChromeVoxPanel::EnterFullscreen() {
104 fullscreen_ = true;
105 UpdateWidgetBounds();
106 }
107
108 void ChromeVoxPanel::ExitFullscreen() {
109 fullscreen_ = false;
110 UpdateWidgetBounds();
111 }
112
113 void ChromeVoxPanel::DisableSpokenFeedback() {
114 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
115 false, ui::A11Y_NOTIFICATION_NONE);
116 }
117
118 const views::Widget* ChromeVoxPanel::GetWidget() const {
119 return widget_;
120 }
121
122 views::Widget* ChromeVoxPanel::GetWidget() {
123 return widget_;
124 }
125
126 void ChromeVoxPanel::DeleteDelegate() {
127 delete this;
128 }
129
130 views::View* ChromeVoxPanel::GetContentsView() {
131 return web_view_;
132 }
133
134 void ChromeVoxPanel::OnDisplayMetricsChanged(const gfx::Display& display,
135 uint32_t changed_metrics) {
136 UpdateWidgetBounds();
137 }
138
139 void ChromeVoxPanel::UpdateWidgetBounds() {
140 gfx::Rect bounds(GetRootWindow()->bounds().size());
141 if (!fullscreen_)
142 bounds.set_height(kPanelHeight);
143 widget_->SetBounds(bounds);
144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698