Commit e7fd177f authored by calamity@chromium.org's avatar calamity@chromium.org

Add icon to the streamlined hosted app creation dialog.

This CL adds an ImageView that displays the icon to the
BookmarkAppBubbleView. It also moves the "Open as tab" checkbox to the
same line as the buttons to save on vertical space which was consumed
by the square icon.

BUG=318607

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255810 0039d316-1c4b-4281-b951-d872f2087c98
parent eed36d56
......@@ -6,6 +6,7 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/app_icon_loader_impl.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h"
......@@ -17,6 +18,7 @@
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h"
......@@ -32,6 +34,8 @@ namespace {
const int kMinBubbleWidth = 300;
// Minimum width of the the textfield.
const int kMinTextfieldWidth = 200;
// Size of the icon.
const int kIconSize = extension_misc::EXTENSION_ICON_MEDIUM;
} // namespace
......@@ -69,7 +73,10 @@ BookmarkAppBubbleView::BookmarkAppBubbleView(
cancel_button_(NULL),
open_as_tab_checkbox_(NULL),
title_tf_(NULL),
remove_app_(true) {
remove_app_(true),
app_icon_loader_(new extensions::AppIconLoaderImpl(profile,
kIconSize,
this)) {
const SkColor background_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DialogBackground);
set_arrow(views::BubbleBorder::TOP_CENTER);
......@@ -111,11 +118,18 @@ void BookmarkAppBubbleView::Init() {
GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
// The column layout used for the text box.
// The column layout used for the icon and text box.
cs = layout->AddColumnSet(TITLE_TEXT_COLUMN_SET_ID);
cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
cs->AddColumn(GridLayout::LEADING,
GridLayout::CENTER,
0,
GridLayout::USE_PREF,
0,
0);
cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
cs->AddColumn(GridLayout::FILL,
GridLayout::FILL,
GridLayout::CENTER,
1,
GridLayout::USE_PREF,
0,
......@@ -124,29 +138,37 @@ void BookmarkAppBubbleView::Init() {
// The column layout used for the row with buttons.
cs = layout->AddColumnSet(CONTENT_COLUMN_SET_ID);
cs->AddPaddingColumn(1, views::kButtonHEdgeMarginNew);
cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
cs->AddColumn(
GridLayout::LEADING, GridLayout::TRAILING, 0, GridLayout::USE_PREF, 0, 0);
GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
cs->AddColumn(
GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
cs->AddColumn(
GridLayout::LEADING, GridLayout::TRAILING, 0, GridLayout::USE_PREF, 0, 0);
GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
layout->StartRow(0, TITLE_COLUMN_SET_ID);
layout->AddView(title_label);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
layout->StartRow(0, TITLE_TEXT_COLUMN_SET_ID);
title_tf_ = new views::Textfield();
const extensions::Extension* extension =
profile_->GetExtensionService()->GetInstalledExtension(extension_id_);
layout->StartRow(0, TITLE_TEXT_COLUMN_SET_ID);
icon_image_view_ = new views::ImageView();
icon_image_view_->SetImageSize(gfx::Size(kIconSize, kIconSize));
layout->AddView(icon_image_view_);
app_icon_loader_->FetchImage(extension_id_);
title_tf_ = new views::Textfield();
title_tf_->SetText(extension ? base::UTF8ToUTF16(extension->name())
: web_app_info_.title);
layout->AddView(title_tf_);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
layout->StartRow(0, TITLE_COLUMN_SET_ID);
layout->StartRow(0, CONTENT_COLUMN_SET_ID);
open_as_tab_checkbox_ = new views::Checkbox(
l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB));
open_as_tab_checkbox_->SetChecked(
......@@ -154,9 +176,6 @@ void BookmarkAppBubbleView::Init() {
extensions::pref_names::kBookmarkAppCreationLaunchType) ==
extensions::LAUNCH_TYPE_REGULAR);
layout->AddView(open_as_tab_checkbox_);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
layout->StartRow(0, CONTENT_COLUMN_SET_ID);
layout->AddView(add_button_);
layout->AddView(cancel_button_);
layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
......@@ -203,6 +222,12 @@ void BookmarkAppBubbleView::ButtonPressed(views::Button* sender,
HandleButtonPressed(sender);
}
void BookmarkAppBubbleView::SetAppImage(const std::string& id,
const gfx::ImageSkia& image) {
DCHECK_EQ(extension_id_, id);
icon_image_view_->SetImage(image);
}
void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) {
// Unset |remove_app_| so we don't delete the bookmark after the window
// closes.
......
......@@ -7,14 +7,24 @@
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "chrome/browser/extensions/app_icon_loader.h"
#include "chrome/common/web_application_info.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
class Profile;
namespace extensions {
class AppIconLoader;
}
namespace gfx {
class ImageSkia;
}
namespace views {
class Checkbox;
class ImageView;
class LabelButton;
class Textfield;
}
......@@ -24,7 +34,8 @@ class Textfield;
// is created with. Don't create a BookmarkAppBubbleView directly, instead use
// the static ShowBubble method.
class BookmarkAppBubbleView : public views::BubbleDelegateView,
public views::ButtonListener {
public views::ButtonListener,
public extensions::AppIconLoader::Delegate {
public:
virtual ~BookmarkAppBubbleView();
......@@ -56,6 +67,10 @@ class BookmarkAppBubbleView : public views::BubbleDelegateView,
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// Overridden from extensions::AppIconLoader::Delegate:
virtual void SetAppImage(const std::string& id,
const gfx::ImageSkia& image) OVERRIDE;
// Handle the message when the user presses a button.
void HandleButtonPressed(views::Button* sender);
......@@ -86,9 +101,15 @@ class BookmarkAppBubbleView : public views::BubbleDelegateView,
// Textfield showing the title of the app.
views::Textfield* title_tf_;
// Image showing the icon of the app.
views::ImageView* icon_image_view_;
// When the destructor is invoked should the app be removed?
bool remove_app_;
// Used to load the icon.
scoped_ptr<extensions::AppIconLoader> app_icon_loader_;
DISALLOW_COPY_AND_ASSIGN(BookmarkAppBubbleView);
};
......
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