Commit e4f22c7a authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Hide the title in the title bar for ARC apps

As is said in the bug, we decided not to show the title in the
title bar for ARC apps. However, debugging information (stored
in extra_title_) wants to appear, and the overview mode wants
to show the actual title (app name) instead of the debugging
information.

So this CL changed ClientControlledShellSurface as:
- GetWindowTitle always return extra_title_ and no title_ so
  title won't appear anymore
- when the widget's title is updated, directly specify the
  native window's title which is used by the overview mode

Bug: 831383
Test: manually, exo_unittests
Change-Id: Ifa275bd6f5c72b8ca36cccf7f9c629498c4a670e
Reviewed-on: https://chromium-review.googlesource.com/1012783
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551529}
parent 947ca034
...@@ -390,6 +390,10 @@ gfx::Rect CustomFrameViewAsh::GetClientBoundsForWindowBounds( ...@@ -390,6 +390,10 @@ gfx::Rect CustomFrameViewAsh::GetClientBoundsForWindowBounds(
return client_bounds; return client_bounds;
} }
base::string16 CustomFrameViewAsh::GetFrameTitle() const {
return frame_->widget_delegate()->GetWindowTitle();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh, views::NonClientFrameView overrides: // CustomFrameViewAsh, views::NonClientFrameView overrides:
...@@ -424,6 +428,7 @@ void CustomFrameViewAsh::ResetWindowControls() { ...@@ -424,6 +428,7 @@ void CustomFrameViewAsh::ResetWindowControls() {
void CustomFrameViewAsh::UpdateWindowIcon() {} void CustomFrameViewAsh::UpdateWindowIcon() {}
void CustomFrameViewAsh::UpdateWindowTitle() { void CustomFrameViewAsh::UpdateWindowTitle() {
header_view_->set_title(GetFrameTitle());
header_view_->SchedulePaintForTitle(); header_view_->SchedulePaintForTitle();
} }
......
...@@ -88,6 +88,9 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView, ...@@ -88,6 +88,9 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
gfx::Rect GetClientBoundsForWindowBounds( gfx::Rect GetClientBoundsForWindowBounds(
const gfx::Rect& window_bounds) const; const gfx::Rect& window_bounds) const;
// Returns the title string which should be shown in the frame.
virtual base::string16 GetFrameTitle() const;
// views::NonClientFrameView: // views::NonClientFrameView:
gfx::Rect GetBoundsForClientView() const override; gfx::Rect GetBoundsForClientView() const override;
gfx::Rect GetWindowBoundsForClientBounds( gfx::Rect GetWindowBoundsForClientBounds(
......
...@@ -145,7 +145,7 @@ void DefaultFrameHeader::PaintHeader(gfx::Canvas* canvas, Mode mode) { ...@@ -145,7 +145,7 @@ void DefaultFrameHeader::PaintHeader(gfx::Canvas* canvas, Mode mode) {
mode_ == MODE_INACTIVE && !UsesCustomFrameColors()) { mode_ == MODE_INACTIVE && !UsesCustomFrameColors()) {
PaintHighlightForInactiveRestoredWindow(canvas); PaintHighlightForInactiveRestoredWindow(canvas);
} }
if (frame_->widget_delegate()->ShouldShowWindowTitle()) if (frame_->widget_delegate()->ShouldShowWindowTitle() && !title_.empty())
PaintTitleBar(canvas); PaintTitleBar(canvas);
if (!UsesCustomFrameColors()) if (!UsesCustomFrameColors())
PaintHeaderContentSeparator(canvas); PaintHeaderContentSeparator(canvas);
...@@ -315,7 +315,7 @@ void DefaultFrameHeader::PaintTitleBar(gfx::Canvas* canvas) { ...@@ -315,7 +315,7 @@ void DefaultFrameHeader::PaintTitleBar(gfx::Canvas* canvas) {
// The window icon is painted by its own views::View. // The window icon is painted by its own views::View.
gfx::Rect title_bounds = GetAvailableTitleBounds(); gfx::Rect title_bounds = GetAvailableTitleBounds();
title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); title_bounds.set_x(view_->GetMirroredXForRect(title_bounds));
canvas->DrawStringRect(frame_->widget_delegate()->GetWindowTitle(), canvas->DrawStringRect(title_,
views::NativeWidgetAura::GetWindowTitleFontList(), views::NativeWidgetAura::GetWindowTitleFontList(),
GetTitleColor(), title_bounds); GetTitleColor(), title_bounds);
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/compiler_specific.h" // override #include "base/compiler_specific.h" // override
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
...@@ -63,6 +64,8 @@ class ASH_EXPORT DefaultFrameHeader : public FrameHeader, ...@@ -63,6 +64,8 @@ class ASH_EXPORT DefaultFrameHeader : public FrameHeader,
} }
FrameCaptionButton* back_button() { return back_button_; } FrameCaptionButton* back_button() { return back_button_; }
void set_title(const base::string16& title) { title_ = title; }
// Sets the active and inactive frame colors. Note the inactive frame color // Sets the active and inactive frame colors. Note the inactive frame color
// will have some transparency added when the frame is drawn. // will have some transparency added when the frame is drawn.
void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color); void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color);
...@@ -126,6 +129,7 @@ class ASH_EXPORT DefaultFrameHeader : public FrameHeader, ...@@ -126,6 +129,7 @@ class ASH_EXPORT DefaultFrameHeader : public FrameHeader,
SkColor active_frame_color_; SkColor active_frame_color_;
SkColor inactive_frame_color_; SkColor inactive_frame_color_;
FrameCaptionButtonContainerView* caption_button_container_; FrameCaptionButtonContainerView* caption_button_container_;
base::string16 title_;
// The height of the header to paint. // The height of the header to paint.
int painted_height_; int painted_height_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/frame/default_frame_header.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h" #include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h"
#include "ash/public/interfaces/window_style.mojom.h" #include "ash/public/interfaces/window_style.mojom.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h" #include "ash/wm/tablet_mode/tablet_mode_observer.h"
...@@ -98,6 +99,10 @@ class ASH_EXPORT HeaderView : public views::View, ...@@ -98,6 +99,10 @@ class ASH_EXPORT HeaderView : public views::View,
bool in_immersive_mode() const { return in_immersive_mode_; } bool in_immersive_mode() const { return in_immersive_mode_; }
void set_title(const base::string16& title) {
frame_header_->set_title(title);
}
void SetShouldPaintHeader(bool paint); void SetShouldPaintHeader(bool paint);
FrameCaptionButton* GetBackButton(); FrameCaptionButton* GetBackButton();
......
...@@ -458,7 +458,8 @@ void ClientControlledShellSurface::SetExtraTitle( ...@@ -458,7 +458,8 @@ void ClientControlledShellSurface::SetExtraTitle(
const base::string16& extra_title) { const base::string16& extra_title) {
TRACE_EVENT1("exo", "ClientControlledShellSurface::SetExtraTitle", TRACE_EVENT1("exo", "ClientControlledShellSurface::SetExtraTitle",
"extra_title", base::UTF16ToUTF8(extra_title)); "extra_title", base::UTF16ToUTF8(extra_title));
extra_title_ = extra_title; // The extra title is used in the window frame.
frame_title_ = extra_title;
if (widget_) if (widget_)
widget_->UpdateWindowTitle(); widget_->UpdateWindowTitle();
} }
...@@ -632,16 +633,6 @@ bool ClientControlledShellSurface::CanMaximize() const { ...@@ -632,16 +633,6 @@ bool ClientControlledShellSurface::CanMaximize() const {
return can_maximize_; return can_maximize_;
} }
base::string16 ClientControlledShellSurface::GetWindowTitle() const {
base::string16 title = ShellSurfaceBase::GetWindowTitle();
if (!extra_title_.empty()) {
if (!title.empty())
title += base::UTF8ToUTF16(" ");
title += extra_title_;
}
return title;
}
views::NonClientFrameView* views::NonClientFrameView*
ClientControlledShellSurface::CreateNonClientFrameView(views::Widget* widget) { ClientControlledShellSurface::CreateNonClientFrameView(views::Widget* widget) {
ash::wm::WindowState* window_state = GetWindowState(); ash::wm::WindowState* window_state = GetWindowState();
......
...@@ -186,7 +186,6 @@ class ClientControlledShellSurface ...@@ -186,7 +186,6 @@ class ClientControlledShellSurface
// Overridden from views::WidgetDelegate: // Overridden from views::WidgetDelegate:
bool CanMaximize() const override; bool CanMaximize() const override;
base::string16 GetWindowTitle() const override;
views::NonClientFrameView* CreateNonClientFrameView( views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) override; views::Widget* widget) override;
void SaveWindowPlacement(const gfx::Rect& bounds, void SaveWindowPlacement(const gfx::Rect& bounds,
...@@ -274,7 +273,6 @@ class ClientControlledShellSurface ...@@ -274,7 +273,6 @@ class ClientControlledShellSurface
uint32_t frame_visible_button_mask_ = 0; uint32_t frame_visible_button_mask_ = 0;
uint32_t frame_enabled_button_mask_ = 0; uint32_t frame_enabled_button_mask_ = 0;
base::string16 extra_title_;
StateChangedCallback state_changed_callback_; StateChangedCallback state_changed_callback_;
BoundsChangedCallback bounds_changed_callback_; BoundsChangedCallback bounds_changed_callback_;
......
...@@ -1062,17 +1062,27 @@ TEST_F(ClientControlledShellSurfaceTest, SetExtraTitle) { ...@@ -1062,17 +1062,27 @@ TEST_F(ClientControlledShellSurfaceTest, SetExtraTitle) {
surface->Attach(buffer.get()); surface->Attach(buffer.get());
surface->Commit(); surface->Commit();
shell_surface->SetExtraTitle(base::string16(base::ASCIIToUTF16("extra"))); // NativeWindow's title is used within the overview mode. It should be the
EXPECT_EQ(base::string16(base::ASCIIToUTF16("extra")), // specified title, as ShellSurface does. On the other hand, the frame's
shell_surface->GetWindowTitle()); // GetWindowTitle() should return the extra -- showing the debugging info
// in the title bar but otherwise it should have empty string.
shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("title"))); // See https://crbug.com/831383.
EXPECT_EQ(base::string16(base::ASCIIToUTF16("title extra")), const aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
shell_surface->GetWindowTitle()); const ash::CustomFrameViewAsh* frame =
static_cast<const ash::CustomFrameViewAsh*>(
shell_surface->SetExtraTitle(base::string16(base::ASCIIToUTF16(""))); shell_surface->GetWidget()->non_client_view()->frame_view());
EXPECT_EQ(base::string16(base::ASCIIToUTF16("title")),
shell_surface->GetWindowTitle()); shell_surface->SetExtraTitle(base::ASCIIToUTF16("extra"));
EXPECT_EQ(base::string16(), window->GetTitle());
EXPECT_EQ(base::ASCIIToUTF16("extra"), frame->GetFrameTitle());
shell_surface->SetTitle(base::ASCIIToUTF16("title"));
EXPECT_EQ(base::ASCIIToUTF16("title"), window->GetTitle());
EXPECT_EQ(base::ASCIIToUTF16("extra"), frame->GetFrameTitle());
shell_surface->SetExtraTitle(base::string16());
EXPECT_EQ(base::ASCIIToUTF16("title"), window->GetTitle());
EXPECT_EQ(base::string16(), frame->GetFrameTitle());
} }
TEST_F(ClientControlledShellSurfaceTest, WideFrame) { TEST_F(ClientControlledShellSurfaceTest, WideFrame) {
......
...@@ -108,7 +108,11 @@ class CustomFrameView : public ash::CustomFrameViewAsh { ...@@ -108,7 +108,11 @@ class CustomFrameView : public ash::CustomFrameViewAsh {
~CustomFrameView() override {} ~CustomFrameView() override {}
// Overridden from ash::CustomFrameViewAshBase: // Overridden from ash::CustomFrameViewAsh:
base::string16 GetFrameTitle() const override {
return static_cast<ShellSurfaceBase*>(GetWidget()->widget_delegate())
->frame_title();
}
void SetShouldPaintHeader(bool paint) override { void SetShouldPaintHeader(bool paint) override {
if (visible()) { if (visible()) {
CustomFrameViewAsh::SetShouldPaintHeader(paint); CustomFrameViewAsh::SetShouldPaintHeader(paint);
......
...@@ -103,6 +103,8 @@ class ShellSurfaceBase : public SurfaceTreeHost, ...@@ -103,6 +103,8 @@ class ShellSurfaceBase : public SurfaceTreeHost,
// Set title for the surface. // Set title for the surface.
void SetTitle(const base::string16& title); void SetTitle(const base::string16& title);
const base::string16& frame_title() const { return frame_title_; }
// Set icon for the surface. // Set icon for the surface.
void SetIcon(const gfx::ImageSkia& icon); void SetIcon(const gfx::ImageSkia& icon);
...@@ -307,6 +309,8 @@ class ShellSurfaceBase : public SurfaceTreeHost, ...@@ -307,6 +309,8 @@ class ShellSurfaceBase : public SurfaceTreeHost,
bool shadow_bounds_changed_ = false; bool shadow_bounds_changed_ = false;
std::unique_ptr<ash::WindowResizer> resizer_; std::unique_ptr<ash::WindowResizer> resizer_;
base::string16 title_; base::string16 title_;
// The title string shown in the window frame (title bar).
base::string16 frame_title_;
std::unique_ptr<ui::CompositorLock> configure_compositor_lock_; std::unique_ptr<ui::CompositorLock> configure_compositor_lock_;
ConfigureCallback configure_callback_; ConfigureCallback configure_callback_;
// TODO(oshima): Remove this once the transition to new drag/resize // TODO(oshima): Remove this once the transition to new drag/resize
......
...@@ -227,11 +227,26 @@ TEST_F(ShellSurfaceTest, SetFullscreen) { ...@@ -227,11 +227,26 @@ TEST_F(ShellSurfaceTest, SetFullscreen) {
} }
TEST_F(ShellSurfaceTest, SetTitle) { TEST_F(ShellSurfaceTest, SetTitle) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface); std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test"))); shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test")));
surface->Attach(buffer.get());
surface->Commit(); surface->Commit();
// NativeWindow's title is used within the overview mode, so it should
// have the specified title.
EXPECT_EQ(base::ASCIIToUTF16("test"),
shell_surface->GetWidget()->GetNativeWindow()->GetTitle());
const ash::CustomFrameViewAsh* frame =
static_cast<const ash::CustomFrameViewAsh*>(
shell_surface->GetWidget()->non_client_view()->frame_view());
// Frame's title is the string to be shown in the title bar. This should be
// empty.
EXPECT_EQ(base::string16(), frame->GetFrameTitle());
} }
TEST_F(ShellSurfaceTest, SetApplicationId) { TEST_F(ShellSurfaceTest, SetApplicationId) {
......
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