Commit 30b01917 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

OopAsh: respond to WM-initiated changes in fullscreen state.

This means Chrome will enter immersive when the user presses
the fullscreen key (F4 on a normal keyboard --- although F4
on a normal keyboard doesn't actually work right now because
event rewriters aren't functioning in OopAsh).

The way this works in classic Ash is via
BrowserWindowStateDelegate, which isn't used in OopAsh.

Bug: 640365
Change-Id: I3b7e7a8911c5d8cba48f2d770e74104dba61e9e2
Reviewed-on: https://chromium-review.googlesource.com/1156995Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579998}
parent c99913a5
......@@ -111,18 +111,30 @@ void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) {
browser_view_ = browser_view;
controller_->Init(this, browser_view_->frame(),
browser_view_->top_container());
observed_windows_.Add(
features::IsAshInBrowserProcess()
? browser_view_->GetNativeWindow()
: browser_view_->GetNativeWindow()->GetRootWindow());
}
void ImmersiveModeControllerAsh::SetEnabled(bool enabled) {
if (controller_->IsEnabled() == enabled)
return;
EnableWindowObservers(enabled);
if (registrar_.IsEmpty()) {
content::Source<FullscreenController> source(
browser_view_->browser()
->exclusive_access_manager()
->fullscreen_controller());
registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source);
}
controller_->SetEnabled(browser_view_->browser()->is_app() ?
ash::ImmersiveFullscreenController::WINDOW_TYPE_HOSTED_APP :
ash::ImmersiveFullscreenController::WINDOW_TYPE_BROWSER
, enabled);
controller_->SetEnabled(
browser_view_->browser()->is_app()
? ash::ImmersiveFullscreenController::WINDOW_TYPE_HOSTED_APP
: ash::ImmersiveFullscreenController::WINDOW_TYPE_BROWSER,
enabled);
}
bool ImmersiveModeControllerAsh::IsEnabled() const {
......@@ -191,28 +203,6 @@ void ImmersiveModeControllerAsh::OnWidgetActivationChanged(
active || !widget->IsMinimized());
}
void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) {
if (observers_enabled_ == enable)
return;
observers_enabled_ = enable;
aura::Window* native_window = browser_view_->GetNativeWindow();
aura::Window* target_window = !features::IsAshInBrowserProcess()
? native_window->GetRootWindow()
: native_window;
content::Source<FullscreenController> source(browser_view_->browser()
->exclusive_access_manager()
->fullscreen_controller());
if (enable) {
target_window->AddObserver(this);
registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source);
} else {
target_window->RemoveObserver(this);
registrar_.Remove(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source);
}
}
void ImmersiveModeControllerAsh::LayoutBrowserRootView() {
views::Widget* widget = browser_view_->frame();
// Update the window caption buttons.
......@@ -349,12 +339,14 @@ void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window,
window->GetProperty(aura::client::kShowStateKey);
auto old_state = static_cast<ui::WindowShowState>(old);
// Disable immersive fullscreen when the user exits fullscreen without going
// through FullscreenController::ToggleBrowserFullscreenMode(). This is the
// case if the user exits fullscreen via the restore button.
if (controller_->IsEnabled() && new_state != ui::SHOW_STATE_FULLSCREEN &&
new_state != ui::SHOW_STATE_MINIMIZED &&
// Make sure the browser stays up to date with the window's state. This is
// necessary in classic Ash if the user exits fullscreen with the restore
// button, and it's necessary in OopAsh if the window manager initiates a
// fullscreen mode change (e.g. due to a WM shortcut).
if (new_state == ui::SHOW_STATE_FULLSCREEN ||
old_state == ui::SHOW_STATE_FULLSCREEN) {
// If the browser view initiated this state change,
// BrowserView::ProcessFullscreen will no-op, so this call is harmless.
browser_view_->FullscreenStateChanged();
}
}
......@@ -363,5 +355,6 @@ void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window,
void ImmersiveModeControllerAsh::OnWindowDestroying(aura::Window* window) {
// Clean up observers here rather than in the destructor because the owning
// BrowserView has already destroyed the aura::Window.
EnableWindowObservers(false);
observed_windows_.Remove(window);
DCHECK(!observed_windows_.IsObservingSources());
}
......@@ -10,6 +10,7 @@
#include "ash/public/cpp/immersive/immersive_fullscreen_controller.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......@@ -50,10 +51,6 @@ class ImmersiveModeControllerAsh
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
private:
// Enables or disables observers for window restore and entering / exiting
// tab fullscreen.
void EnableWindowObservers(bool enable);
// Updates the browser root view's layout including window caption controls.
void LayoutBrowserRootView();
......@@ -87,10 +84,6 @@ class ImmersiveModeControllerAsh
BrowserView* browser_view_ = nullptr;
// True if the observers for window restore and entering / exiting tab
// fullscreen are enabled.
bool observers_enabled_ = false;
// The current visible bounds of the find bar, in screen coordinates. This is
// an empty rect if the find bar is not visible.
gfx::Rect find_bar_visible_bounds_in_screen_;
......@@ -105,6 +98,8 @@ class ImmersiveModeControllerAsh
content::NotificationRegistrar registrar_;
ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_{this};
DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment