forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show ChromeVox caption panel when spoken feedback is enabled.
This adds a widget to the top of the screen that shows the ChromeVox caption panel whenever spoken feedback is enabled. It automatically waits for the web content to load before showing it to avoid flicker. Depends on: https://codereview.chromium.org/1277183003/ BUG=420795 Review URL: https://codereview.chromium.org/1274563004 Cr-Commit-Position: refs/heads/master@{#359499}
- Loading branch information
1 parent
1f28f36
commit 94a4f88
Showing
8 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
chrome/browser/chromeos/accessibility/chromevox_panel.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// 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/shelf/shelf_layout_manager.h" | ||
#include "ash/shell.h" | ||
#include "ash/shell_window_ids.h" | ||
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | ||
#include "chrome/browser/chromeos/accessibility/chromevox_panel.h" | ||
#include "chrome/common/extensions/extension_constants.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/chromeos/accessibility_types.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"; | ||
const char kDisableSpokenFeedbackURLFragment[] = "close"; | ||
|
||
} // namespace | ||
|
||
class ChromeVoxPanelWebContentsObserver : public content::WebContentsObserver { | ||
public: | ||
ChromeVoxPanelWebContentsObserver(content::WebContents* web_contents, | ||
ChromeVoxPanel* panel) | ||
: content::WebContentsObserver(web_contents), panel_(panel) {} | ||
~ChromeVoxPanelWebContentsObserver() override {} | ||
|
||
// content::WebContentsObserver overrides. | ||
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 == kDisableSpokenFeedbackURLFragment) | ||
panel_->DisableSpokenFeedback(); | ||
else if (fragment == kFullscreenURLFragment) | ||
panel_->EnterFullscreen(); | ||
else | ||
panel_->ExitFullscreen(); | ||
} | ||
|
||
private: | ||
ChromeVoxPanel* panel_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebContentsObserver); | ||
}; | ||
|
||
ChromeVoxPanel::ChromeVoxPanel(content::BrowserContext* browser_context) | ||
: widget_(nullptr), web_view_(nullptr), fullscreen_(false) { | ||
std::string url("chrome-extension://"); | ||
url += extension_misc::kChromeVoxExtensionId; | ||
url += kChromeVoxPanelRelativeUrl; | ||
|
||
views::WebView* web_view = new views::WebView(browser_context); | ||
web_contents_observer_.reset( | ||
new ChromeVoxPanelWebContentsObserver(web_view->GetWebContents(), this)); | ||
web_view->LoadInitialURL(GURL(url)); | ||
web_view_ = web_view; | ||
|
||
widget_ = new views::Widget(); | ||
views::Widget::InitParams params( | ||
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | ||
aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); | ||
params.parent = ash::Shell::GetContainer( | ||
root_window, ash::kShellWindowId_SettingBubbleContainer); | ||
params.delegate = this; | ||
params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | ||
params.bounds = gfx::Rect(0, 0, root_window->bounds().width(), | ||
root_window->bounds().height()); | ||
widget_->Init(params); | ||
SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR); | ||
|
||
ash::Shell::GetScreen()->AddObserver(this); | ||
} | ||
|
||
ChromeVoxPanel::~ChromeVoxPanel() { | ||
ash::Shell::GetScreen()->RemoveObserver(this); | ||
} | ||
|
||
aura::Window* ChromeVoxPanel::GetRootWindow() { | ||
return GetWidget()->GetNativeWindow()->GetRootWindow(); | ||
} | ||
|
||
void ChromeVoxPanel::Close() { | ||
widget_->Close(); | ||
} | ||
|
||
void ChromeVoxPanel::DidFirstVisuallyNonEmptyPaint() { | ||
widget_->Show(); | ||
ash::ShelfLayoutManager::ForShelf(GetRootWindow()) | ||
->SetChromeVoxPanelHeight(kPanelHeight); | ||
} | ||
|
||
void ChromeVoxPanel::EnterFullscreen() { | ||
fullscreen_ = true; | ||
UpdateWidgetBounds(); | ||
} | ||
|
||
void ChromeVoxPanel::ExitFullscreen() { | ||
fullscreen_ = false; | ||
UpdateWidgetBounds(); | ||
} | ||
|
||
void ChromeVoxPanel::DisableSpokenFeedback() { | ||
chromeos::AccessibilityManager::Get()->EnableSpokenFeedback( | ||
false, ui::A11Y_NOTIFICATION_NONE); | ||
} | ||
|
||
const views::Widget* ChromeVoxPanel::GetWidget() const { | ||
return widget_; | ||
} | ||
|
||
views::Widget* ChromeVoxPanel::GetWidget() { | ||
return widget_; | ||
} | ||
|
||
void ChromeVoxPanel::DeleteDelegate() { | ||
delete this; | ||
} | ||
|
||
views::View* ChromeVoxPanel::GetContentsView() { | ||
return web_view_; | ||
} | ||
|
||
void ChromeVoxPanel::OnDisplayMetricsChanged(const gfx::Display& display, | ||
uint32_t changed_metrics) { | ||
UpdateWidgetBounds(); | ||
} | ||
|
||
void ChromeVoxPanel::UpdateWidgetBounds() { | ||
gfx::Rect bounds(GetRootWindow()->bounds().size()); | ||
if (!fullscreen_) | ||
bounds.set_height(kPanelHeight); | ||
widget_->SetBounds(bounds); | ||
} |
Oops, something went wrong.