Chromium Code Reviews| 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 "chrome/browser/chromeos/accessibility/chromevox_panel.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/common/extensions/extension_constants.h" | |
| 9 #include "content/public/browser/web_contents.h" | |
| 10 #include "ui/views/controls/webview/webview.h" | |
| 11 #include "ui/views/layout/fill_layout.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 #include "ui/wm/core/shadow_types.h" | |
| 14 #include "ui/wm/core/window_animations.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const int kPanelHeight = 35; | |
| 19 const char kChromeVoxPanelRelativeUrl[] = "/cvox2/background/panel.html"; | |
| 20 const char kFullscreenURLFragment[] = "fullscreen"; | |
| 21 | |
| 22 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.
| |
| 23 public: | |
| 24 ChromeVoxPanelWebView(Profile* profile, ChromeVoxPanel* panel) | |
| 25 : views::WebView(profile), panel_(panel) {} | |
| 26 | |
| 27 ~ChromeVoxPanelWebView() override {} | |
| 28 | |
| 29 void OnDeviceScaleFactorChanged(float device_scale_factor) override { | |
| 30 panel_->OnDeviceScaleFactorChanged(device_scale_factor); | |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 ChromeVoxPanel* panel_; | |
| 35 bool fullscreen_; | |
|
Jun Mukai
2015/11/05 17:38:02
not used?
dmazzoni
2015/11/05 20:12:58
Done.
| |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebView); | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 class ChromeVoxPanelWebContentsObserver : public content::WebContentsObserver { | |
| 43 public: | |
| 44 ChromeVoxPanelWebContentsObserver(content::WebContents* web_contents, | |
| 45 ChromeVoxPanel* panel) | |
| 46 : content::WebContentsObserver(web_contents), panel_(panel) {} | |
| 47 ~ChromeVoxPanelWebContentsObserver() override {} | |
| 48 | |
| 49 void DidFirstVisuallyNonEmptyPaint() override { | |
| 50 panel_->DidFirstVisuallyNonEmptyPaint(); | |
| 51 } | |
| 52 | |
| 53 void DidFinishNavigation( | |
| 54 content::NavigationHandle* navigation_handle) override { | |
| 55 // The ChromeVox panel uses the URL fragment to communicate state | |
| 56 // to this panel host. | |
| 57 std::string fragment = web_contents()->GetLastCommittedURL().ref(); | |
| 58 if (fragment == kFullscreenURLFragment) | |
| 59 panel_->EnterFullscreen(); | |
| 60 else | |
| 61 panel_->ExitFullscreen(); | |
| 62 } | |
| 63 | |
| 64 private: | |
| 65 ChromeVoxPanel* panel_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWebContentsObserver); | |
| 68 }; | |
| 69 | |
| 70 ChromeVoxPanel::ChromeVoxPanel(Profile* profile) : profile_(profile) { | |
| 71 widget_ = new views::Widget(); | |
| 72 views::Widget::InitParams params( | |
| 73 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 74 root_window_ = ash::Shell::GetPrimaryRootWindow(); | |
| 75 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.
| |
| 76 params.delegate = this; | |
| 77 widget_->Init(params); | |
| 78 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.
| |
| 79 | |
| 80 std::string url("chrome-extension://"); | |
| 81 url += extension_misc::kChromeVoxExtensionId; | |
| 82 url += kChromeVoxPanelRelativeUrl; | |
| 83 | |
| 84 ChromeVoxPanelWebView* web_view = new ChromeVoxPanelWebView(profile_, this); | |
| 85 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.
| |
| 86 SetShadowType(widget_->GetNativeWindow(), wm::SHADOW_TYPE_RECTANGULAR); | |
| 87 web_contents_observer_.reset( | |
| 88 new ChromeVoxPanelWebContentsObserver(web_view->GetWebContents(), this)); | |
| 89 web_view->LoadInitialURL(GURL(url)); | |
| 90 | |
| 91 ash::Shell::GetScreen()->AddObserver(this); | |
| 92 } | |
| 93 | |
| 94 ChromeVoxPanel::~ChromeVoxPanel() { | |
| 95 ash::Shell::GetScreen()->RemoveObserver(this); | |
| 96 } | |
| 97 | |
| 98 int ChromeVoxPanel::GetHeight() { | |
| 99 return kPanelHeight; | |
| 100 } | |
| 101 | |
| 102 aura::Window* ChromeVoxPanel::GetRootWindow() { | |
| 103 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.
| |
| 104 } | |
| 105 | |
| 106 void ChromeVoxPanel::Close() { | |
| 107 widget_->Close(); | |
| 108 } | |
| 109 | |
| 110 void ChromeVoxPanel::OnDeviceScaleFactorChanged(float device_scale_factor) { | |
| 111 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.
| |
| 112 } | |
| 113 | |
| 114 void ChromeVoxPanel::DidFirstVisuallyNonEmptyPaint() { | |
| 115 widget_->Show(); | |
| 116 ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_); | |
| 117 } | |
| 118 | |
| 119 void ChromeVoxPanel::EnterFullscreen() { | |
| 120 fullscreen_ = true; | |
| 121 UpdateWidgetBounds(); | |
| 122 } | |
| 123 | |
| 124 void ChromeVoxPanel::ExitFullscreen() { | |
| 125 fullscreen_ = false; | |
| 126 UpdateWidgetBounds(); | |
| 127 } | |
| 128 | |
| 129 const views::Widget* ChromeVoxPanel::GetWidget() const { | |
| 130 return widget_; | |
| 131 } | |
| 132 | |
| 133 views::Widget* ChromeVoxPanel::GetWidget() { | |
| 134 return widget_; | |
| 135 } | |
| 136 | |
| 137 void ChromeVoxPanel::DeleteDelegate() { | |
| 138 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
| |
| 139 delete this; | |
| 140 } | |
| 141 | |
| 142 void ChromeVoxPanel::OnDisplayMetricsChanged(const gfx::Display& display, | |
| 143 uint32_t changed_metrics) { | |
| 144 // This is called when the primary display changes. Move the panel to the | |
| 145 // new primary display. | |
| 146 if (root_window_ != ash::Shell::GetPrimaryRootWindow()) { | |
| 147 UpdateWidgetBounds(); | |
| 148 ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_); | |
| 149 root_window_ = ash::Shell::GetPrimaryRootWindow(); | |
| 150 ash::Shell::GetInstance()->UpdateDisplayWorkAreaInsets(root_window_); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 void ChromeVoxPanel::UpdateWidgetBounds() { | |
| 155 gfx::Rect bounds(0, 0, root_window_->bounds().width(), | |
| 156 root_window_->bounds().height()); | |
| 157 if (!fullscreen_) | |
| 158 bounds.set_height(kPanelHeight); | |
| 159 widget_->SetBounds(bounds); | |
| 160 } | |
| OLD | NEW |