Commit 9a5fd60b authored by benwells@chromium.org's avatar benwells@chromium.org

Create a prominent omnibox UI element to add pages to the app launcher.

This is experimental and behind a flag. It does not currently do
anything except allow us to explore what kind of UI we want.

BUG=378171

Review URL: https://codereview.chromium.org/324043002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276608 0039d316-1c4b-4281-b951-d872f2087c98
parent 221a732f
...@@ -13831,6 +13831,12 @@ Do you accept? ...@@ -13831,6 +13831,12 @@ Do you accept?
OEM folder OEM folder
</message> </message>
</if> </if>
<message name="IDS_ADD_TO_APP_LIST_NOTIFICATION_TEXT" desc="Text explaining that the current site can be added to the App Launcher.">
This page can be added to the App Launcher
</message>
<message name="IDS_ADD_TO_APP_LIST_HINT" desc="Hint text for the button allowing the current site to be added to the App Launcher.">
Add to the App Launcher
</message>
<if expr="use_titlecase"> <if expr="use_titlecase">
<message name="IDS_APP_LIST_CONTEXT_MENU_NEW_TAB" desc="Title text for the 'open new' context menu item of an app list item configured to open in a tab"> <message name="IDS_APP_LIST_CONTEXT_MENU_NEW_TAB" desc="Title text for the 'open new' context menu item of an app list item configured to open in a tab">
New Tab New Tab
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/location_bar/add_to_app_launcher_view.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_utils.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "url/gurl.h"
namespace {
// TODO(benwells): Refactor common code between this and
// ContentSettingImageView.
const int kBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE);
const int kStayOpenTimeMS = 3200; // Time spent with animation fully open.
const int kOpenTimeMS = 150;
const int kAnimationDurationMS = (kOpenTimeMS * 2) + kStayOpenTimeMS;
// Amount of padding at the edges of the bubble. If |by_icon| is true, this
// is the padding next to the icon; otherwise it's the padding next to the
// label. (We increase padding next to the label by the amount of padding
// "built in" to the icon in order to make the bubble appear to have
// symmetrical padding.)
int GetBubbleOuterPadding(bool by_icon) {
return LocationBarView::kItemPadding - LocationBarView::kBubblePadding +
(by_icon ? 0 : LocationBarView::kIconInternalPadding);
}
int GetTotalSpacingWhileAnimating() {
return GetBubbleOuterPadding(true) + LocationBarView::kItemPadding +
GetBubbleOuterPadding(false);
}
} // namespace
AddToAppLauncherView::AddToAppLauncherView(LocationBarView* parent,
const gfx::FontList& font_list,
SkColor text_color,
SkColor parent_background_color)
: parent_(parent),
background_painter_(
views::Painter::CreateImageGridPainter(kBackgroundImages)),
icon_(new views::ImageView),
text_label_(new views::Label(base::string16(), font_list)),
slide_animator_(this) {
icon_->SetHorizontalAlignment(views::ImageView::LEADING);
icon_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_BOOKMARK_BAR_APPS_SHORTCUT));
icon_->SetTooltipText(
base::UTF8ToUTF16(l10n_util::GetStringUTF8(IDS_ADD_TO_APP_LIST_HINT)));
AddChildView(icon_);
text_label_->SetVisible(false);
text_label_->SetEnabledColor(text_color);
// Calculate the actual background color for the label. The background images
// are painted atop |parent_background_color|. We grab the color of the
// middle pixel of the middle image of the background, which we treat as the
// representative color of the entire background (reasonable, given the
// current appearance of these images). Then we alpha-blend it over the
// parent background color to determine the actual color the label text will
// sit atop.
const SkBitmap& bitmap(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
kBackgroundImages[4])->GetRepresentation(1.0f).sk_bitmap());
SkAutoLockPixels pixel_lock(bitmap);
SkColor background_image_color =
bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2);
// Tricky bit: We alpha blend an opaque version of |background_image_color|
// against |parent_background_color| using the original image grid color's
// alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
// even if |a| is a color with non-255 alpha.
text_label_->SetBackgroundColor(
color_utils::AlphaBlend(SkColorSetA(background_image_color, 255),
parent_background_color,
SkColorGetA(background_image_color)));
text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
text_label_->SetElideBehavior(gfx::TRUNCATE);
text_label_->SetText(base::UTF8ToUTF16(
l10n_util::GetStringUTF8(IDS_ADD_TO_APP_LIST_NOTIFICATION_TEXT)));
AddChildView(text_label_);
slide_animator_.SetSlideDuration(kAnimationDurationMS);
slide_animator_.SetTweenType(gfx::Tween::LINEAR);
}
AddToAppLauncherView::~AddToAppLauncherView() {
}
void AddToAppLauncherView::Update(content::WebContents* web_contents) {
SetVisible(false);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kEnableProminentURLAppFlow) ||
!command_line->HasSwitch(switches::kEnableStreamlinedHostedApps) ||
!web_contents || web_contents->IsLoading() ||
!web_contents->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
slide_animator_.Reset();
return;
}
SetVisible(true);
if (!slide_animator_.is_animating()) {
text_label_->SetVisible(true);
slide_animator_.Show();
}
}
void AddToAppLauncherView::AnimationEnded(const gfx::Animation* animation) {
slide_animator_.Reset();
text_label_->SetVisible(false);
AnimationProgressed(animation);
}
void AddToAppLauncherView::AnimationProgressed(
const gfx::Animation* animation) {
parent_->Layout();
parent_->SchedulePaint();
}
void AddToAppLauncherView::AnimationCanceled(const gfx::Animation* animation) {
AnimationEnded(animation);
}
gfx::Size AddToAppLauncherView::GetPreferredSize() const {
// Height will be ignored by the LocationBarView.
gfx::Size size(icon_->GetPreferredSize());
if (slide_animator_.is_animating()) {
double state = slide_animator_.GetCurrentValue();
// The fraction of the animation we'll spend animating the string into view,
// which is also the fraction we'll spend animating it closed; total
// animation (slide out, show, then slide in) is 1.0.
const double kOpenFraction =
static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
double size_fraction = 1.0;
if (state < kOpenFraction)
size_fraction = state / kOpenFraction;
if (state > (1.0 - kOpenFraction))
size_fraction = (1.0 - state) / kOpenFraction;
size.Enlarge(
size_fraction * (text_label_->GetPreferredSize().width() +
GetTotalSpacingWhileAnimating()), 0);
size.SetToMax(background_painter_->GetMinimumSize());
}
return size;
}
void AddToAppLauncherView::Layout() {
const int icon_width = icon_->GetPreferredSize().width();
icon_->SetBounds(
std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)),
0,
icon_width,
height());
text_label_->SetBounds(
icon_->bounds().right() + LocationBarView::kItemPadding,
0,
std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0),
height());
}
void AddToAppLauncherView::OnPaintBackground(gfx::Canvas* canvas) {
if (slide_animator_.is_animating())
background_painter_->Paint(canvas, size());
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ADD_TO_APP_LAUNCHER_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ADD_TO_APP_LAUNCHER_VIEW_H_
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/views/painter.h"
#include "ui/views/view.h"
class LocationBarView;
namespace content {
class WebContents;
}
namespace gfx {
class FontList;
}
namespace views {
class ImageView;
class Label;
}
// The AddToAppLauncherView displays a UI in the location bar to allow adding
// the current page to the App Launcher.
class AddToAppLauncherView : public gfx::AnimationDelegate, public views::View {
public:
AddToAppLauncherView(LocationBarView* parent,
const gfx::FontList& font_list,
SkColor text_color,
SkColor parent_background_color);
virtual ~AddToAppLauncherView();
// Updates the decoration from the shown WebContents.
void Update(content::WebContents* web_contents);
private:
// gfx::AnimationDelegate:
virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE;
// views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
LocationBarView* parent_; // Weak, owns us.
scoped_ptr<views::Painter> background_painter_;
views::ImageView* icon_;
views::Label* text_label_;
gfx::SlideAnimation slide_animator_;
DISALLOW_COPY_AND_ASSIGN(AddToAppLauncherView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ADD_TO_APP_LAUNCHER_VIEW_H_
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/browser_dialogs.h" #include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/browser/ui/views/location_bar/add_to_app_launcher_view.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h"
...@@ -221,6 +222,7 @@ LocationBarView::LocationBarView(Browser* browser, ...@@ -221,6 +222,7 @@ LocationBarView::LocationBarView(Browser* browser,
open_pdf_in_reader_view_(NULL), open_pdf_in_reader_view_(NULL),
manage_passwords_icon_view_(NULL), manage_passwords_icon_view_(NULL),
translate_icon_view_(NULL), translate_icon_view_(NULL),
add_to_app_launcher_view_(NULL),
star_view_(NULL), star_view_(NULL),
search_button_(NULL), search_button_(NULL),
is_popup_mode_(is_popup_mode), is_popup_mode_(is_popup_mode),
...@@ -389,6 +391,11 @@ void LocationBarView::Init() { ...@@ -389,6 +391,11 @@ void LocationBarView::Init() {
translate_icon_view_->SetVisible(false); translate_icon_view_->SetVisible(false);
AddChildView(translate_icon_view_); AddChildView(translate_icon_view_);
add_to_app_launcher_view_ = new AddToAppLauncherView(
this, bubble_font_list, text_color, background_color);
add_to_app_launcher_view_->SetVisible(false);
AddChildView(add_to_app_launcher_view_);
star_view_ = new StarView(command_updater()); star_view_ = new StarView(command_updater());
star_view_->SetVisible(false); star_view_->SetVisible(false);
AddChildView(star_view_); AddChildView(star_view_);
...@@ -688,7 +695,8 @@ gfx::Size LocationBarView::GetPreferredSize() const { ...@@ -688,7 +695,8 @@ gfx::Size LocationBarView::GetPreferredSize() const {
IncrementalMinimumWidth(manage_passwords_icon_view_) + IncrementalMinimumWidth(manage_passwords_icon_view_) +
IncrementalMinimumWidth(zoom_view_) + IncrementalMinimumWidth(zoom_view_) +
IncrementalMinimumWidth(generated_credit_card_view_) + IncrementalMinimumWidth(generated_credit_card_view_) +
IncrementalMinimumWidth(mic_search_view_) + kItemPadding; IncrementalMinimumWidth(mic_search_view_) +
IncrementalMinimumWidth(add_to_app_launcher_view_) + kItemPadding;
for (PageActionViews::const_iterator i(page_action_views_.begin()); for (PageActionViews::const_iterator i(page_action_views_.begin());
i != page_action_views_.end(); ++i) i != page_action_views_.end(); ++i)
trailing_width += IncrementalMinimumWidth((*i)); trailing_width += IncrementalMinimumWidth((*i));
...@@ -773,6 +781,10 @@ void LocationBarView::Layout() { ...@@ -773,6 +781,10 @@ void LocationBarView::Layout() {
trailing_decorations.AddDecoration( trailing_decorations.AddDecoration(
vertical_edge_thickness(), location_height, star_view_); vertical_edge_thickness(), location_height, star_view_);
} }
if (add_to_app_launcher_view_->visible()) {
trailing_decorations.AddDecoration(
vertical_edge_thickness(), location_height, add_to_app_launcher_view_);
}
if (translate_icon_view_->visible()) { if (translate_icon_view_->visible()) {
trailing_decorations.AddDecoration( trailing_decorations.AddDecoration(
vertical_edge_thickness(), location_height, translate_icon_view_); vertical_edge_thickness(), location_height, translate_icon_view_);
...@@ -1052,8 +1064,10 @@ void LocationBarView::Update(const WebContents* contents) { ...@@ -1052,8 +1064,10 @@ void LocationBarView::Update(const WebContents* contents) {
RefreshPageActionViews(); RefreshPageActionViews();
RefreshTranslateIcon(); RefreshTranslateIcon();
RefreshManagePasswordsIconView(); RefreshManagePasswordsIconView();
open_pdf_in_reader_view_->Update( content::WebContents* web_contents_for_sub_views =
GetToolbarModel()->input_in_progress() ? NULL : GetWebContents()); GetToolbarModel()->input_in_progress() ? NULL : GetWebContents();
open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
add_to_app_launcher_view_->Update(web_contents_for_sub_views);
if (star_view_) { if (star_view_) {
star_view_->SetVisible( star_view_->SetVisible(
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "ui/views/drag_controller.h" #include "ui/views/drag_controller.h"
class ActionBoxButtonView; class ActionBoxButtonView;
class AddToAppLauncherView;
class CommandUpdater; class CommandUpdater;
class ContentSettingBubbleModelDelegate; class ContentSettingBubbleModelDelegate;
class ContentSettingImageView; class ContentSettingImageView;
...@@ -495,6 +496,9 @@ class LocationBarView : public LocationBar, ...@@ -495,6 +496,9 @@ class LocationBarView : public LocationBar,
// The icon for Translate. // The icon for Translate.
TranslateIconView* translate_icon_view_; TranslateIconView* translate_icon_view_;
// The view to add pages to the app launcher.
AddToAppLauncherView* add_to_app_launcher_view_;
// The star. // The star.
StarView* star_view_; StarView* star_view_;
......
...@@ -1756,14 +1756,16 @@ ...@@ -1756,14 +1756,16 @@
'browser/ui/views/javascript_app_modal_dialog_views.h', 'browser/ui/views/javascript_app_modal_dialog_views.h',
'browser/ui/views/load_complete_listener.cc', 'browser/ui/views/load_complete_listener.cc',
'browser/ui/views/load_complete_listener.h', 'browser/ui/views/load_complete_listener.h',
'browser/ui/views/location_bar/add_to_app_launcher_view.cc',
'browser/ui/views/location_bar/add_to_app_launcher_view.h',
'browser/ui/views/location_bar/bubble_icon_view.cc', 'browser/ui/views/location_bar/bubble_icon_view.cc',
'browser/ui/views/location_bar/bubble_icon_view.h', 'browser/ui/views/location_bar/bubble_icon_view.h',
'browser/ui/views/location_bar/generated_credit_card_view.cc',
'browser/ui/views/location_bar/generated_credit_card_view.h',
'browser/ui/views/location_bar/content_setting_image_view.cc', 'browser/ui/views/location_bar/content_setting_image_view.cc',
'browser/ui/views/location_bar/content_setting_image_view.h', 'browser/ui/views/location_bar/content_setting_image_view.h',
'browser/ui/views/location_bar/ev_bubble_view.cc', 'browser/ui/views/location_bar/ev_bubble_view.cc',
'browser/ui/views/location_bar/ev_bubble_view.h', 'browser/ui/views/location_bar/ev_bubble_view.h',
'browser/ui/views/location_bar/generated_credit_card_view.cc',
'browser/ui/views/location_bar/generated_credit_card_view.h',
'browser/ui/views/location_bar/icon_label_bubble_view.cc', 'browser/ui/views/location_bar/icon_label_bubble_view.cc',
'browser/ui/views/location_bar/icon_label_bubble_view.h', 'browser/ui/views/location_bar/icon_label_bubble_view.h',
'browser/ui/views/location_bar/keyword_hint_view.cc', 'browser/ui/views/location_bar/keyword_hint_view.cc',
......
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