Commit 35c25b65 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

cros: Paint headers for snap window when in both splitview and overview.

Fix a bug where snapped windows in splitview while still in overview
do not have their headers painted. Make CustomFrameViewAshBase look for
splitview state changes, and repaint the header if the state is snap
left or snap right.

Test: ash_unittests CustomFrameViewAshTest.HeaderVisibility*
Bug: 789378
Change-Id: I7ff65181134205544af2a717a3ee3e3797aa2ad2
Reviewed-on: https://chromium-review.googlesource.com/797681
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521114}
parent db31c228
......@@ -15,6 +15,7 @@
#include "ash/public/cpp/immersive/immersive_fullscreen_controller.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h"
#include "ash/shell.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/resize_handle_window_targeter.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h"
......@@ -322,10 +323,13 @@ CustomFrameViewAsh::CustomFrameViewAsh(
enable_immersive)));
}
Shell::Get()->AddShellObserver(this);
Shell::Get()->split_view_controller()->AddObserver(this);
}
CustomFrameViewAsh::~CustomFrameViewAsh() {
Shell::Get()->RemoveShellObserver(this);
if (Shell::Get()->split_view_controller())
Shell::Get()->split_view_controller()->RemoveObserver(this);
}
void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
......@@ -477,6 +481,26 @@ const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
return header_view_->avatar_icon();
}
void CustomFrameViewAsh::MaybePaintHeaderForSplitview(
SplitViewController::State state) {
if (state == SplitViewController::NO_SNAP) {
header_view_->SetShouldPaintHeader(/*paint=*/false);
return;
}
SplitViewController* controller = Shell::Get()->split_view_controller();
aura::Window* window = nullptr;
if (state == SplitViewController::LEFT_SNAPPED)
window = controller->left_window();
else if (state == SplitViewController::RIGHT_SNAPPED)
window = controller->right_window();
// TODO(sammiequon): This works for now, but we may have to check if
// |frame_|'s native window is in the overview list instead.
if (window && window == frame_->GetNativeWindow())
header_view_->SetShouldPaintHeader(/*paint=*/true);
}
void CustomFrameViewAsh::SetShouldPaintHeader(bool paint) {
header_view_->SetShouldPaintHeader(paint);
}
......@@ -489,6 +513,13 @@ void CustomFrameViewAsh::OnOverviewModeEnded() {
SetShouldPaintHeader(true);
}
void CustomFrameViewAsh::OnSplitViewStateChanged(
SplitViewController::State /* previous_state */,
SplitViewController::State state) {
if (Shell::Get()->window_selector_controller()->IsSelecting())
MaybePaintHeaderForSplitview(state);
}
////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh, private:
......
......@@ -10,6 +10,7 @@
#include "ash/ash_export.h"
#include "ash/public/interfaces/window_style.mojom.h"
#include "ash/shell_observer.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "base/macros.h"
#include "base/optional.h"
#include "third_party/skia/include/core/SkColor.h"
......@@ -39,7 +40,8 @@ enum class FrameBackButtonState {
// the top of the screen. See also views::CustomFrameView and
// BrowserNonClientFrameViewAsh.
class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
public ash::ShellObserver {
public ShellObserver,
public SplitViewController::Observer {
public:
// Internal class name.
static const char kViewClassName[];
......@@ -100,15 +102,24 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
void SchedulePaintInRect(const gfx::Rect& r) override;
void SetVisible(bool visible) override;
// Called when splitview state changes. Depending on |state| and if the window
// associated with |widget_| is the snapped window, paint the header in
// overview mode.
void MaybePaintHeaderForSplitview(SplitViewController::State state);
// If |paint| is false, we should not paint the header. Used for overview mode
// with OnOverviewModeStarting() and OnOverviewModeEnded() to hide/show the
// header of v2 and ARC apps.
virtual void SetShouldPaintHeader(bool paint);
// ash::ShellObserver:
// ShellObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
// SplitViewController::Observer:
void OnSplitViewStateChanged(SplitViewController::State previous_state,
SplitViewController::State state) override;
const views::View* GetAvatarIconViewForTest() const;
private:
......
......@@ -13,9 +13,11 @@
#include "ash/frame/header_view.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/test/event_generator.h"
......@@ -45,6 +47,8 @@ class CustomFrameTestWidgetDelegate : public views::WidgetDelegateView {
CustomFrameViewAsh* custom_frame_view() const { return custom_frame_view_; }
HeaderView* header_view() const { return custom_frame_view_->header_view_; }
private:
// Not owned.
CustomFrameViewAsh* custom_frame_view_;
......@@ -316,6 +320,63 @@ TEST_F(CustomFrameViewAshTest, OpeningAppsInTabletMode) {
delegate->GetCustomFrameViewTopBorderHeight());
}
TEST_F(CustomFrameViewAshTest, HeaderVisibilityInOverviewMode) {
auto* delegate = new CustomFrameTestWidgetDelegate();
auto* widget = new views::Widget();
views::Widget::InitParams params;
params.context = CurrentContext();
params.delegate = delegate;
widget->Init(params);
widget->Show();
// Verify the header is not painted in overview mode and painted when not in
// overview mode.
Shell::Get()->window_selector_controller()->ToggleOverview();
EXPECT_FALSE(delegate->header_view()->should_paint());
Shell::Get()->window_selector_controller()->ToggleOverview();
EXPECT_TRUE(delegate->header_view()->should_paint());
}
TEST_F(CustomFrameViewAshTest, HeaderVisibilityInSplitview) {
auto set_up_widget = [this](CustomFrameTestWidgetDelegate* delegate,
views::Widget* widget) {
views::Widget::InitParams params;
params.context = CurrentContext();
params.delegate = delegate;
widget->Init(params);
widget->Show();
// Windows need to be resizable and maximizable to be used in splitview.
widget->GetNativeWindow()->SetProperty(
aura::client::kResizeBehaviorKey,
ui::mojom::kResizeBehaviorCanMaximize |
ui::mojom::kResizeBehaviorCanResize);
};
auto* delegate1 = new CustomFrameTestWidgetDelegate();
auto* widget1 = new views::Widget();
auto* delegate2 = new CustomFrameTestWidgetDelegate();
auto* widget2 = new views::Widget();
set_up_widget(delegate1, widget1);
set_up_widget(delegate2, widget2);
// Verify that when one window is snapped, the header is drawn for the snapped
// window, but not drawn for the window still in overview.
Shell::Get()->window_selector_controller()->ToggleOverview();
Shell::Get()->split_view_controller()->SnapWindow(widget1->GetNativeWindow(),
SplitViewController::LEFT);
EXPECT_TRUE(delegate1->header_view()->should_paint());
EXPECT_FALSE(delegate2->header_view()->should_paint());
// Verify that when both windows are snapped, the header is drawn for both.
Shell::Get()->split_view_controller()->SnapWindow(widget2->GetNativeWindow(),
SplitViewController::RIGHT);
EXPECT_TRUE(delegate1->header_view()->should_paint());
EXPECT_TRUE(delegate2->header_view()->should_paint());
Shell::Get()->split_view_controller()->EndSplitView();
}
namespace {
class TestTarget : public ui::AcceleratorTarget {
......
......@@ -51,6 +51,8 @@ class ASH_EXPORT HeaderView : public views::View,
FrameCaptionButton* back_button() { return back_button_; }
bool should_paint() { return should_paint_; }
// Schedules a repaint for the entire title.
void SchedulePaintForTitle();
......
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