Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / location_bar / location_bar_view.cc
index a741785..2362075 100644 (file)
 #include "chrome/browser/extensions/location_bar_controller.h"
 #include "chrome/browser/extensions/tab_helper.h"
 #include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/search/instant_service.h"
+#include "chrome/browser/search/instant_service_factory.h"
 #include "chrome/browser/search/search.h"
 #include "chrome/browser/search_engines/template_url.h"
 #include "chrome/browser/search_engines/template_url_service.h"
 #include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/browser/translate/translate_manager.h"
+#include "chrome/browser/translate/translate_service.h"
 #include "chrome/browser/translate/translate_tab_helper.h"
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/browser_finder.h"
 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
-#include "chrome/browser/ui/views/toolbar/site_chip_view.h"
+#include "chrome/browser/ui/views/toolbar/origin_chip_view.h"
 #include "chrome/browser/ui/zoom/zoom_controller.h"
 #include "chrome/common/chrome_switches.h"
 #include "chrome/common/pref_names.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/render_widget_host_view.h"
 #include "content/public/browser/web_contents.h"
+#include "extensions/browser/extension_system.h"
 #include "extensions/common/feature_switch.h"
 #include "extensions/common/permissions/permissions_data.h"
 #include "grit/generated_resources.h"
@@ -146,7 +149,7 @@ gfx::FontList GetLargestFontListWithHeightBound(
     const int space_at_bottom = height - (y_offset + font_list.GetHeight());
     if ((y_offset >= 0) && (space_at_bottom >= 0))
       break;
-    font_list = font_list.DeriveFontListWithSizeDelta(-1);
+    font_list = font_list.DeriveWithSizeDelta(-1);
   }
   return font_list;
 }
@@ -206,7 +209,7 @@ LocationBarView::LocationBarView(Browser* browser,
       generated_credit_card_view_(NULL),
       open_pdf_in_reader_view_(NULL),
       manage_passwords_icon_view_(NULL),
-      site_chip_view_(NULL),
+      origin_chip_view_(NULL),
       translate_icon_view_(NULL),
       star_view_(NULL),
       search_button_(NULL),
@@ -261,8 +264,10 @@ void LocationBarView::Init() {
       ResourceBundle::BaseFont);
   const int current_font_size = font_list.GetFontSize();
   const int desired_font_size = browser_defaults::kOmniboxFontPixelSize;
-  if (current_font_size < desired_font_size)
-    font_list = font_list.DeriveFontListWithSize(desired_font_size);
+  if (current_font_size != desired_font_size) {
+    font_list =
+        font_list.DeriveWithSizeDelta(desired_font_size - current_font_size);
+  }
   // Shrink large fonts to make them fit.
   // TODO(pkasting): Stretch the location bar instead in this case.
   const int location_height = GetInternalHeight(true);
@@ -732,7 +737,7 @@ void LocationBarView::Layout() {
         selected_keyword_view_->set_is_extension_icon(false);
       }
     }
-  } else if (!site_chip_view_ &&
+  } else if (!origin_chip_view_ &&
       (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) {
     ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName());
     // The largest fraction of the omnibox that can be taken by the EV bubble.
@@ -960,9 +965,6 @@ void LocationBarView::OnPaint(gfx::Canvas* canvas) {
 
   // The border itself will be drawn in PaintChildren() since it includes an
   // inner shadow which should be drawn over the contents.
-
-  if (!is_popup_mode_)
-    PaintPageActionBackgrounds(canvas);
 }
 
 void LocationBarView::SetShowFocusRect(bool show) {
@@ -975,13 +977,13 @@ void LocationBarView::SelectAll() {
 }
 
 views::ImageView* LocationBarView::GetLocationIconView() {
-  return site_chip_view_ ?
-      site_chip_view_->location_icon_view() : location_icon_view_;
+  return origin_chip_view_ ?
+      origin_chip_view_->location_icon_view() : location_icon_view_;
 }
 
 const views::ImageView* LocationBarView::GetLocationIconView() const {
-  return site_chip_view_ ?
-      site_chip_view_->location_icon_view() : location_icon_view_;
+  return origin_chip_view_ ?
+      origin_chip_view_->location_icon_view() : location_icon_view_;
 }
 
 views::View* LocationBarView::GetLocationBarAnchor() {
@@ -1052,8 +1054,8 @@ void LocationBarView::OnChanged() {
       *GetThemeProvider()->GetImageSkiaNamed((icon_id == IDR_OMNIBOX_SEARCH) ?
           IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW));
 
-  if (site_chip_view_)
-    site_chip_view_->OnChanged();
+  if (origin_chip_view_)
+    origin_chip_view_->OnChanged();
 
   Layout();
   SchedulePaint();
@@ -1111,8 +1113,9 @@ void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) {
 }
 
 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
-  if (browser_ && browser_->instant_controller() && parent())
-    browser_->instant_controller()->SetOmniboxBounds(bounds());
+  InstantServiceFactory::GetForProfile(profile())->OnOmniboxStartMarginChanged(
+      bounds().x());
+
   OmniboxPopupView* popup = omnibox_view_->model()->popup_model()->view();
   if (popup->IsOpen())
     popup->UpdatePopupAppearance();
@@ -1474,7 +1477,7 @@ bool LocationBarView::RefreshManagePasswordsIconView() {
 }
 
 void LocationBarView::RefreshTranslateIcon() {
-  if (!TranslateManager::IsTranslateBubbleEnabled())
+  if (!TranslateService::IsTranslateBubbleEnabled())
     return;
 
   WebContents* web_contents = GetWebContents();
@@ -1513,39 +1516,6 @@ void LocationBarView::ShowFirstRunBubbleInternal() {
 #endif
 }
 
-void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) {
-  WebContents* web_contents = GetWebContents();
-  // web_contents may be NULL while the browser is shutting down.
-  if (!web_contents)
-    return;
-
-  const int32 tab_id = SessionID::IdForTab(web_contents);
-  const ToolbarModel::SecurityLevel security_level =
-      GetToolbarModel()->GetSecurityLevel(false);
-  const SkColor text_color = GetColor(security_level, TEXT);
-  const SkColor background_color = GetColor(security_level, BACKGROUND);
-
-  for (PageActionViews::const_iterator
-           page_action_view = page_action_views_.begin();
-       page_action_view != page_action_views_.end();
-       ++page_action_view) {
-    gfx::Rect bounds = (*page_action_view)->bounds();
-    int horizontal_padding =
-        GetItemPadding() - GetBuiltInHorizontalPaddingForChildViews();
-    // Make the bounding rectangle include the whole vertical range of the
-    // location bar, and the mid-point pixels between adjacent page actions.
-    //
-    // For odd horizontal_paddings, "horizontal_padding + 1" includes the
-    // mid-point between two page actions in the bounding rectangle.  For even
-    // paddings, the +1 is dropped, which is right since there is no pixel at
-    // the mid-point.
-    bounds.Inset(-(horizontal_padding + 1) / 2, 0);
-    location_bar_util::PaintExtensionActionBackground(
-        *(*page_action_view)->image_view()->page_action(),
-        tab_id, canvas, bounds, text_color, background_color);
-  }
-}
-
 void LocationBarView::AccessibilitySetValue(const base::string16& new_value) {
   omnibox_view_->SetUserText(new_value, new_value, true);
 }