Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / frame / glass_browser_frame_view.cc
index 58f112b..75a0087 100644 (file)
@@ -4,34 +4,30 @@
 
 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
 
-#include "base/command_line.h"
 #include "base/prefs/pref_service.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/app/chrome_command_ids.h"
 #include "chrome/app/chrome_dll_resource.h"
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profiles_state.h"
+#include "chrome/browser/signin/signin_header_helper.h"
 #include "chrome/browser/themes/theme_properties.h"
-#include "chrome/browser/ui/views/avatar_menu_button.h"
 #include "chrome/browser/ui/views/frame/browser_view.h"
-#include "chrome/browser/ui/views/new_avatar_button.h"
+#include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
+#include "chrome/browser/ui/views/profiles/new_avatar_button.h"
 #include "chrome/browser/ui/views/tabs/tab.h"
 #include "chrome/browser/ui/views/tabs/tab_strip.h"
-#include "chrome/browser/ui/views/toolbar_view.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
+#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
+#include "components/signin/core/common/profile_management_switches.h"
 #include "content/public/browser/notification_service.h"
-#include "grit/generated_resources.h"
 #include "grit/theme_resources.h"
-#include "grit/ui_resources.h"
-#include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle_win.h"
 #include "ui/base/theme_provider.h"
 #include "ui/gfx/canvas.h"
 #include "ui/gfx/icon_util.h"
 #include "ui/gfx/image/image.h"
 #include "ui/gfx/win/dpi.h"
+#include "ui/resources/grit/ui_resources.h"
 #include "ui/views/controls/label.h"
 #include "ui/views/layout/layout_constants.h"
 #include "ui/views/win/hwnd_util.h"
@@ -89,8 +85,7 @@ GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
   if (browser_view->ShouldShowWindowIcon())
     InitThrobberIcons();
 
-  if (browser_view->IsRegularOrGuestSession() &&
-      profiles::IsNewProfileManagementEnabled())
+  if (browser_view->IsRegularOrGuestSession() && switches::IsNewAvatarMenu())
     UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON);
   else
     UpdateAvatarInfo();
@@ -115,8 +110,16 @@ gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
   // The new avatar button is optionally displayed to the left of the
   // minimize button.
   if (new_avatar_button()) {
-    DCHECK(profiles::IsNewProfileManagementEnabled());
-    minimize_button_offset -= new_avatar_button()->width();
+    DCHECK(switches::IsNewAvatarMenu());
+    minimize_button_offset -=
+        new_avatar_button()->width() + kNewAvatarButtonOffset;
+
+    // In non-maximized mode, allow the new tab button to completely slide under
+    // the avatar button.
+    if (!frame()->IsMaximized() && !base::i18n::IsRTL()) {
+      minimize_button_offset +=
+          TabStrip::kNewTabButtonAssetWidth + kNewTabCaptionRestoredSpacing;
+    }
   }
 
   int tabstrip_x = browser_view()->ShouldShowAvatar() ?
@@ -128,28 +131,25 @@ gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
   // a tab strip until the left end of this window without considering the size
   // of window controls in RTL languages.
   if (base::i18n::IsRTL()) {
-    if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized())
+    if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) {
       tabstrip_x += avatar_bounds_.x();
-    else if (browser_view()->IsRegularOrGuestSession() &&
-        profiles::IsNewProfileManagementEnabled())
+    else if (browser_view()->IsRegularOrGuestSession() &&
+               switches::IsNewAvatarMenu()) {
       tabstrip_x = width() - minimize_button_offset;
+    }
 
     minimize_button_offset = width();
   }
   int tabstrip_width = minimize_button_offset - tabstrip_x -
       (frame()->IsMaximized() ?
           kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
-  return gfx::Rect(tabstrip_x, GetTabStripInsets(false).top,
+  return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(),
                    std::max(0, tabstrip_width),
                    tabstrip->GetPreferredSize().height());
 }
 
-BrowserNonClientFrameView::TabStripInsets
-GlassBrowserFrameView::GetTabStripInsets(bool restored) const {
-  if (!browser_view()->IsTabStripVisible())
-    return TabStripInsets();
-  // TODO: include OTR and caption.
-  return TabStripInsets(NonClientTopBorderHeight(restored), 0, 0);
+int GlassBrowserFrameView::GetTopInset() const {
+  return GetClientAreaInsets().top();
 }
 
 int GlassBrowserFrameView::GetThemeBackgroundXInset() const {
@@ -168,7 +168,7 @@ void GlassBrowserFrameView::UpdateThrobber(bool running) {
   }
 }
 
-gfx::Size GlassBrowserFrameView::GetMinimumSize() {
+gfx::Size GlassBrowserFrameView::GetMinimumSize() const {
   gfx::Size min_size(browser_view()->GetMinimumSize());
 
   // Account for the client area insets.
@@ -240,9 +240,10 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
   // See if we're in the sysmenu region.  We still have to check the tabstrip
   // first so that clicks in a tab don't get treated as sysmenu clicks.
   int nonclient_border_thickness = NonClientBorderThickness();
-  if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME),
-                GetSystemMetrics(SM_CXSMICON),
-                GetSystemMetrics(SM_CYSMICON)).Contains(point))
+  if (gfx::Rect(nonclient_border_thickness,
+                gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME),
+                gfx::win::GetSystemMetricsInDIP(SM_CXSMICON),
+                gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point))
     return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
 
   if (frame_component != HTNOWHERE)
@@ -269,8 +270,7 @@ void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
 }
 
 void GlassBrowserFrameView::Layout() {
-  if (browser_view()->IsRegularOrGuestSession() &&
-      profiles::IsNewProfileManagementEnabled())
+  if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu())
     LayoutNewStyleAvatar();
   else
     LayoutAvatar();
@@ -278,29 +278,35 @@ void GlassBrowserFrameView::Layout() {
   LayoutClientView();
 }
 
-bool GlassBrowserFrameView::HitTestRect(const gfx::Rect& rect) const {
-  bool hit_avatar_button = avatar_button() &&
-      avatar_button()->GetMirroredBounds().Intersects(rect);
-  bool hit_new_avatar_button = new_avatar_button() &&
-      new_avatar_button()->GetMirroredBounds().Intersects(rect);
-  return hit_avatar_button || hit_new_avatar_button ||
-         !frame()->client_view()->bounds().Intersects(rect);
-}
-
 ///////////////////////////////////////////////////////////////////////////////
 // GlassBrowserFrameView, views::ButtonListener overrides:
 void GlassBrowserFrameView::ButtonPressed(views::Button* sender,
                                           const ui::Event& event) {
-  if (sender == new_avatar_button())
-    ShowProfileChooserViewBubble();
+  if (sender == new_avatar_button()) {
+    browser_view()->ShowAvatarBubbleFromAvatarButton(
+        BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT,
+        signin::ManageAccountsParams());
+  }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // GlassBrowserFrameView, private:
 
+// views::NonClientFrameView:
+bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target,
+                                              const gfx::Rect& rect) const {
+  CHECK_EQ(target, this);
+  bool hit_avatar_button = avatar_button() &&
+      avatar_button()->GetMirroredBounds().Intersects(rect);
+  bool hit_new_avatar_button = new_avatar_button() &&
+      new_avatar_button()->GetMirroredBounds().Intersects(rect);
+  return hit_avatar_button || hit_new_avatar_button ||
+         !frame()->client_view()->bounds().Intersects(rect);
+}
+
 int GlassBrowserFrameView::FrameBorderThickness() const {
   return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
-      0 : GetSystemMetrics(SM_CXSIZEFRAME);
+      0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
 }
 
 int GlassBrowserFrameView::NonClientBorderThickness() const {
@@ -310,16 +316,15 @@ int GlassBrowserFrameView::NonClientBorderThickness() const {
   return kNonClientBorderThickness;
 }
 
-int GlassBrowserFrameView::NonClientTopBorderHeight(
-    bool restored) const {
-  if (!restored && frame()->IsFullscreen())
+int GlassBrowserFrameView::NonClientTopBorderHeight() const {
+  if (frame()->IsFullscreen())
     return 0;
 
   // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
   // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
   // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
   return gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
-      ((!restored && !frame()->ShouldLeaveOffsetNearTopBorder()) ?
+      (!frame()->ShouldLeaveOffsetNearTopBorder() ?
       -kTabstripTopShadowThickness : kNonClientRestoredExtraThickness);
 }
 
@@ -348,7 +353,7 @@ void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
                    : y;
   canvas->TileImageInt(*theme_toolbar,
                        x + GetThemeBackgroundXInset(),
-                       dest_y - GetTabStripInsets(false).top, x,
+                       dest_y - GetTopInset(), x,
                        dest_y, w, theme_toolbar->height());
 
   if (browser_view()->IsTabStripVisible()) {
@@ -445,26 +450,29 @@ void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
 }
 
 void GlassBrowserFrameView::LayoutNewStyleAvatar() {
-  DCHECK(profiles::IsNewProfileManagementEnabled());
+  DCHECK(switches::IsNewAvatarMenu());
   if (!new_avatar_button())
     return;
 
   gfx::Size label_size = new_avatar_button()->GetPreferredSize();
-  int button_size_with_offset = kNewAvatarButtonOffset + label_size.width();
 
   int button_x = frame()->GetMinimizeButtonOffset() -
       kNewAvatarButtonOffset - label_size.width();
-
   if (base::i18n::IsRTL())
     button_x = width() - frame()->GetMinimizeButtonOffset() +
         kNewAvatarButtonOffset;
 
-  int button_y = frame()->IsMaximized() ? NonClientTopBorderHeight(false) : 1;
+  // We need to offset the button correctly in maximized mode, so that the
+  // custom glass style aligns with the native control glass style. The
+  // glass shadow is off by 1px, which was determined by visual inspection.
+  int button_y = !frame()->IsMaximized() ? 1 :
+      NonClientTopBorderHeight() + kTabstripTopShadowThickness - 1;
+
   new_avatar_button()->SetBounds(
       button_x,
       button_y,
       label_size.width(),
-      button_y + gfx::win::GetSystemMetricsInDIP(SM_CXMENUSIZE));
+      gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1);
 }
 
 void GlassBrowserFrameView::LayoutAvatar() {
@@ -481,11 +489,11 @@ void GlassBrowserFrameView::LayoutAvatar() {
   if (base::i18n::IsRTL())
     avatar_x += width() - frame()->GetMinimizeButtonOffset();
 
-  int avatar_bottom = GetTabStripInsets(false).top +
+  int avatar_bottom = GetTopInset() +
       browser_view()->GetTabStripHeight() - kAvatarBottomSpacing;
   int avatar_restored_y = avatar_bottom - incognito_icon.height();
   int avatar_y = frame()->IsMaximized() ?
-      (NonClientTopBorderHeight(false) + kTabstripTopShadowThickness) :
+      (NonClientTopBorderHeight() + kTabstripTopShadowThickness) :
       avatar_restored_y;
   avatar_bounds_.SetRect(avatar_x, avatar_y, incognito_icon.width(),
       browser_view()->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0);
@@ -501,7 +509,7 @@ gfx::Insets GlassBrowserFrameView::GetClientAreaInsets() const {
   if (!browser_view()->IsTabStripVisible())
     return gfx::Insets();
 
-  const int top_height = NonClientTopBorderHeight(false);
+  const int top_height = NonClientTopBorderHeight();
   const int border_thickness = NonClientBorderThickness();
   return gfx::Insets(top_height,
                      border_thickness,
@@ -569,10 +577,11 @@ void GlassBrowserFrameView::Observe(
   switch (type) {
     case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
       if (browser_view()->IsRegularOrGuestSession() &&
-          profiles::IsNewProfileManagementEnabled())
+          switches::IsNewAvatarMenu()) {
         UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON);
-      else
+      } else {
         UpdateAvatarInfo();
+      }
       break;
     default:
       NOTREACHED() << "Got a notification we didn't register for!";