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/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/browser/profiles/profile.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 | |
oshima
2015/11/05 23:58:51
// content::WebContentsObserver
dmazzoni
2015/11/06 17:28:14
Done.
| |
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(Profile* profile) : profile_(profile) { | |
oshima
2015/11/05 23:58:50
can this be just a BrowserContext?
dmazzoni
2015/11/06 17:28:14
Done.
| |
59 std::string url("chrome-extension://"); | |
60 url += extension_misc::kChromeVoxExtensionId; | |
61 url += kChromeVoxPanelRelativeUrl; | |
62 | |
63 web_view_ = new views::WebView(profile_); | |
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 LOG(ERROR) << "ROOT initial: " << root_window; | |
oshima
2015/11/05 23:58:51
remove this.
dmazzoni
2015/11/06 17:28:14
Done.
| |
73 params.parent = ash::Shell::GetContainer( | |
74 root_window, ash::kShellWindowId_SettingBubbleContainer); | |
75 params.delegate = this; | |
76 params.bounds = gfx::Rect(0, 0, root_window->bounds().width(), | |
77 root_window->bounds().height()); | |
78 widget_->Init(params); | |
79 SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR); | |
80 | |
81 ash::Shell::GetScreen()->AddObserver(this); | |
82 } | |
83 | |
84 ChromeVoxPanel::~ChromeVoxPanel() { | |
85 ash::Shell::GetScreen()->RemoveObserver(this); | |
86 } | |
87 | |
88 int ChromeVoxPanel::GetHeight() { | |
89 return kPanelHeight; | |
90 } | |
91 | |
92 aura::Window* ChromeVoxPanel::GetRootWindow() { | |
93 return GetWidget()->GetNativeWindow()->GetRootWindow(); | |
94 } | |
95 | |
96 void ChromeVoxPanel::Close() { | |
97 widget_->Close(); | |
98 } | |
99 | |
100 void ChromeVoxPanel::DidFirstVisuallyNonEmptyPaint() { | |
101 widget_->Show(); | |
102 ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(GetRootWindow()); | |
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 ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(GetRootWindow()); | |
140 } | |
141 | |
142 void ChromeVoxPanel::UpdateWidgetBounds() { | |
143 gfx::Rect bounds(0, 0, GetRootWindow()->bounds().width(), | |
144 GetRootWindow()->bounds().height()); | |
oshima
2015/11/05 23:58:50
bounds(GetRootWindow()->bounds().size());
dmazzoni
2015/11/06 17:28:15
Done.
| |
145 if (!fullscreen_) | |
146 bounds.set_height(kPanelHeight); | |
147 widget_->SetBounds(bounds); | |
148 } | |
OLD | NEW |