Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / frame / browser_non_client_frame_view_ash.cc
index e61ebe3..1bd6967 100644 (file)
@@ -8,6 +8,7 @@
 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h"
 #include "ash/wm/frame_border_hit_test_controller.h"
 #include "ash/wm/header_painter.h"
+#include "base/command_line.h"
 #include "chrome/browser/themes/theme_properties.h"
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/views/avatar_label.h"
@@ -17,6 +18,7 @@
 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
 #include "chrome/browser/ui/views/tab_icon_view.h"
 #include "chrome/browser/ui/views/tabs/tab_strip.h"
+#include "chrome/common/chrome_switches.h"
 #include "content/public/browser/web_contents.h"
 #include "grit/ash_resources.h"
 #include "grit/theme_resources.h"
@@ -101,7 +103,7 @@ void BrowserNonClientFrameViewAsh::Init() {
   // Create incognito icon if necessary.
   UpdateAvatarInfo();
 
-  // Frame painter handles layout.
+  // HeaderPainter handles layout.
   header_painter_->Init(frame(), this, window_icon_, caption_button_container_);
 }
 
@@ -131,7 +133,7 @@ int BrowserNonClientFrameViewAsh::GetTopInset() const {
     return 0;
 
   if (browser_view()->IsTabStripVisible()) {
-    if (UseShortHeader())
+    if (frame()->IsMaximized() || frame()->IsFullscreen())
       return kTabstripTopSpacingShort;
     else
       return kTabstripTopSpacingTall;
@@ -143,7 +145,9 @@ int BrowserNonClientFrameViewAsh::GetTopInset() const {
   if (browser_view()->IsToolbarVisible())
     return caption_buttons_bottom - kContentShadowHeight;
 
-  return caption_buttons_bottom + kClientEdgeThickness;
+  int separator_thickness = UsePackagedAppHeaderStyle() ?
+      header_painter_->HeaderContentSeparatorSize() : kClientEdgeThickness;
+  return caption_buttons_bottom + separator_thickness;
 }
 
 int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const {
@@ -200,7 +204,7 @@ int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
 }
 
 void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size,
-                                                  gfx::Path* window_mask) {
+                                                 gfx::Path* window_mask) {
   // Aura does not use window masks.
 }
 
@@ -261,6 +265,13 @@ void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) {
 }
 
 void BrowserNonClientFrameViewAsh::Layout() {
+  // The header must be laid out before computing |header_height| because the
+  // computation of |header_height| for app and popup windows depends on the
+  // position of the window controls.
+  header_painter_->LayoutHeader(UsePackagedAppHeaderStyle() ||
+                                frame()->IsMaximized() ||
+                                frame()->IsFullscreen());
+
   int header_height = 0;
   if (browser_view()->IsTabStripVisible()) {
     header_height = GetTopInset() +
@@ -273,7 +284,6 @@ void BrowserNonClientFrameViewAsh::Layout() {
     header_height = GetTopInset();
   }
   header_painter_->set_header_height(header_height);
-  header_painter_->LayoutHeader(UseShortHeader());
   if (avatar_button())
     LayoutAvatar();
   BrowserNonClientFrameView::Layout();
@@ -365,14 +375,6 @@ int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const {
   return header_painter_->GetRightInset() + kTabstripRightSpacing;
 }
 
-bool BrowserNonClientFrameViewAsh::UseShortHeader() const {
-  // Restored browser windows use the tall header. All other windows use the
-  // short header.
-  return frame()->IsMaximized() ||
-         frame()->IsFullscreen() ||
-         browser_view()->browser()->is_app();
-}
-
 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
   ImmersiveModeController* immersive_controller =
       browser_view()->immersive_mode_controller();
@@ -381,6 +383,15 @@ bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
       browser_view()->IsTabStripVisible();
 }
 
+bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const {
+  // Non streamlined hosted apps do not have a toolbar or tabstrip. Their header
+  // should look the same as the header for packaged apps. Streamlined hosted
+  // apps have a toolbar so should use the browser header style.
+  return browser_view()->browser()->is_app() &&
+      !CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kEnableStreamlinedHostedApps);
+}
+
 void BrowserNonClientFrameViewAsh::LayoutAvatar() {
   DCHECK(avatar_button());
   DCHECK(browser_view()->IsTabStripVisible());
@@ -503,10 +514,14 @@ void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) {
 }
 
 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) {
-  canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(),
-                             width(), kClientEdgeThickness),
-      ThemeProperties::GetDefaultColor(
-          ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
+  if (UsePackagedAppHeaderStyle()) {
+    header_painter_->PaintHeaderContentSeparator(canvas);
+  } else {
+    canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(),
+                               width(), kClientEdgeThickness),
+        ThemeProperties::GetDefaultColor(
+            ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
+  }
 }
 
 int BrowserNonClientFrameViewAsh::GetThemeFrameImageId() const {