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

Unified 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 missing files 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/accessibility/chromevox_panel.cc
diff --git a/chrome/browser/chromeos/accessibility/chromevox_panel.cc b/chrome/browser/chromeos/accessibility/chromevox_panel.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e8ae000eebbb7aa579afb2b4a071a4b16f68c541
--- /dev/null
+++ b/chrome/browser/chromeos/accessibility/chromevox_panel.cc
@@ -0,0 +1,160 @@
+// Copyright 2015 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/shell.h"
+#include "chrome/browser/chromeos/accessibility/chromevox_panel.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/views/controls/webview/webview.h"
+#include "ui/views/layout/fill_layout.h"
+#include "ui/views/widget/widget.h"
+#include "ui/wm/core/shadow_types.h"
+#include "ui/wm/core/window_animations.h"
+
+namespace {
+
+const int kPanelHeight = 35;
+const char kChromeVoxPanelRelativeUrl[] = "/cvox2/background/panel.html";
+const char kFullscreenURLFragment[] = "fullscreen";
+
+class ChromeVoxPanelWebView : public views::WebView {
Jun Mukai 2015/11/05 17:38:02 As I wrote below, OnDeviceScaleFactorChanged() met
dmazzoni 2015/11/05 20:12:58 Done.
+ public:
+ ChromeVoxPanelWebView(Profile* profile, ChromeVoxPanel* panel)
+ : views::WebView(profile), panel_(panel) {}
+
+ ~ChromeVoxPanelWebView() override {}
+
+ void OnDeviceScaleFactorChanged(float device_scale_factor) override {
+ panel_->OnDeviceScaleFactorChanged(device_scale_factor);
+ }
+
+ private:
+ ChromeVoxPanel* panel_;
+ bool fullscreen_;
Jun Mukai 2015/11/05 17:38:02 not used?
dmazzoni 2015/11/05 20:12:58 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebView);
+};
+
+} // namespace
+
+class ChromeVoxPanelWebContentsObserver : public content::WebContentsObserver {
+ public:
+ ChromeVoxPanelWebContentsObserver(content::WebContents* web_contents,
+ ChromeVoxPanel* panel)
+ : content::WebContentsObserver(web_contents), panel_(panel) {}
+ ~ChromeVoxPanelWebContentsObserver() override {}
+
+ void DidFirstVisuallyNonEmptyPaint() override {
+ panel_->DidFirstVisuallyNonEmptyPaint();
+ }
+
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override {
+ // The ChromeVox panel uses the URL fragment to communicate state
+ // to this panel host.
+ std::string fragment = web_contents()->GetLastCommittedURL().ref();
+ if (fragment == kFullscreenURLFragment)
+ panel_->EnterFullscreen();
+ else
+ panel_->ExitFullscreen();
+ }
+
+ private:
+ ChromeVoxPanel* panel_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebContentsObserver);
+};
+
+ChromeVoxPanel::ChromeVoxPanel(Profile* profile) : profile_(profile) {
+ widget_ = new views::Widget();
+ views::Widget::InitParams params(
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ root_window_ = ash::Shell::GetPrimaryRootWindow();
+ params.parent = root_window_;
Jun Mukai 2015/11/05 17:38:01 Please do not create a window directly under the r
dmazzoni 2015/11/05 20:12:58 Done.
+ params.delegate = this;
+ widget_->Init(params);
+ UpdateWidgetBounds();
Jun Mukai 2015/11/05 17:38:01 IIRC, the initial bounds (set in params) and setti
dmazzoni 2015/11/05 20:12:58 Done.
+
+ std::string url("chrome-extension://");
+ url += extension_misc::kChromeVoxExtensionId;
+ url += kChromeVoxPanelRelativeUrl;
+
+ ChromeVoxPanelWebView* web_view = new ChromeVoxPanelWebView(profile_, this);
+ widget_->SetContentsView(web_view);
Jun Mukai 2015/11/05 17:38:01 It's better to implement GetContentsView() rather
dmazzoni 2015/11/05 20:12:58 Done.
+ SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR);
+ web_contents_observer_.reset(
+ new ChromeVoxPanelWebContentsObserver(web_view->GetWebContents(), this));
+ web_view->LoadInitialURL(GURL(url));
+
+ ash::Shell::GetScreen()->AddObserver(this);
+}
+
+ChromeVoxPanel::~ChromeVoxPanel() {
+ ash::Shell::GetScreen()->RemoveObserver(this);
+}
+
+int ChromeVoxPanel::GetHeight() {
+ return kPanelHeight;
+}
+
+aura::Window* ChromeVoxPanel::GetRootWindow() {
+ return root_window_;
Jun Mukai 2015/11/05 17:38:01 You don't have to remember the root window. It's j
dmazzoni 2015/11/05 20:12:58 Done.
+}
+
+void ChromeVoxPanel::Close() {
+ widget_->Close();
+}
+
+void ChromeVoxPanel::OnDeviceScaleFactorChanged(float device_scale_factor) {
+ UpdateWidgetBounds();
Jun Mukai 2015/11/05 17:38:01 I think you don't have to handle the device scale
dmazzoni 2015/11/05 20:12:58 Done.
+}
+
+void ChromeVoxPanel::DidFirstVisuallyNonEmptyPaint() {
+ widget_->Show();
+ ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_);
+}
+
+void ChromeVoxPanel::EnterFullscreen() {
+ fullscreen_ = true;
+ UpdateWidgetBounds();
+}
+
+void ChromeVoxPanel::ExitFullscreen() {
+ fullscreen_ = false;
+ UpdateWidgetBounds();
+}
+
+const views::Widget* ChromeVoxPanel::GetWidget() const {
+ return widget_;
+}
+
+views::Widget* ChromeVoxPanel::GetWidget() {
+ return widget_;
+}
+
+void ChromeVoxPanel::DeleteDelegate() {
+ ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_);
Jun Mukai 2015/11/05 17:38:02 This may not work quite well. At this point, the w
dmazzoni 2015/11/05 20:12:58 Thanks. I went with the first approach, observing
+ delete this;
+}
+
+void ChromeVoxPanel::OnDisplayMetricsChanged(const gfx::Display& display,
+ uint32_t changed_metrics) {
+ // This is called when the primary display changes. Move the panel to the
+ // new primary display.
+ if (root_window_ != ash::Shell::GetPrimaryRootWindow()) {
+ UpdateWidgetBounds();
+ ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_);
+ root_window_ = ash::Shell::GetPrimaryRootWindow();
+ ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_);
+ }
+}
+
+void ChromeVoxPanel::UpdateWidgetBounds() {
+ gfx::Rect bounds(0, 0, root_window_->bounds().width(),
+ root_window_->bounds().height());
+ if (!fullscreen_)
+ bounds.set_height(kPanelHeight);
+ widget_->SetBounds(bounds);
+}

Powered by Google App Engine
This is Rietveld 408576698