Commit 44c1357d authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Display an app's short name in the app launcher

The app launcher will now display an app's short name (the new
short_name property in the manifest file). If an app's short name
and full name differ, the tooltip will show the full name. If an
app's short name and full name are identical, a tooltip will only
be shown if the title is truncated.

BUG=226848
TEST=If an app has a short name and it differs from its full name,
a tooltip should always be shown, displaying the full name. If an
app does not have a short name override, there should be no change
in behavior, i.e. a tooltip will only be shown if the title is
truncated.

Review URL: https://chromiumcodereview.appspot.com/23709003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221205 0039d316-1c4b-4281-b951-d872f2087c98
parent 0ff99299
......@@ -45,8 +45,9 @@ class WindowTypeLauncherItem : public app_list::AppListItemModel {
};
explicit WindowTypeLauncherItem(Type type) : type_(type) {
std::string title(GetTitle(type));
SetIcon(GetIcon(type), false);
SetTitle(GetTitle(type));
SetTitleAndFullName(title, title);
}
static gfx::ImageSkia GetIcon(Type type) {
......
......@@ -102,11 +102,11 @@ void ExtensionAppItem::Reload() {
SetIsInstalling(is_installing);
set_app_id(extension_id_);
if (is_installing) {
SetTitle(extension_name_);
SetTitleAndFullName(extension_name_, extension_name_);
UpdateIcon();
return;
}
SetTitle(extension->name());
SetTitleAndFullName(extension->short_name(), extension->name());
LoadImage(extension);
}
......
......@@ -24,11 +24,13 @@ void AppListItemModel::SetIcon(const gfx::ImageSkia& icon, bool has_shadow) {
FOR_EACH_OBSERVER(AppListItemModelObserver, observers_, ItemIconChanged());
}
void AppListItemModel::SetTitle(const std::string& title) {
if (title_ == title)
void AppListItemModel::SetTitleAndFullName(const std::string& title,
const std::string& full_name) {
if (title_ == title && full_name_ == full_name)
return;
title_ = title;
full_name_ = full_name;
FOR_EACH_OBSERVER(AppListItemModelObserver, observers_, ItemTitleChanged());
}
......
......@@ -31,8 +31,10 @@ class APP_LIST_EXPORT AppListItemModel {
const gfx::ImageSkia& icon() const { return icon_; }
bool has_shadow() const { return has_shadow_; }
void SetTitle(const std::string& title);
void SetTitleAndFullName(const std::string& title,
const std::string& full_name);
const std::string& title() const { return title_; }
const std::string& full_name() const { return full_name_; }
void SetHighlighted(bool highlighted);
bool highlighted() const { return highlighted_; }
......@@ -58,6 +60,7 @@ class APP_LIST_EXPORT AppListItemModel {
gfx::ImageSkia icon_;
bool has_shadow_;
std::string title_;
std::string full_name_;
bool highlighted_;
bool is_installing_;
int percent_downloaded_;
......
......@@ -125,7 +125,7 @@ class AppListItemWithMenu : public AppListItemModel {
AppListItemWithMenu(const std::string& title)
: menu_model_(NULL),
menu_ready_(true) {
SetTitle(title);
SetTitleAndFullName(title, title);
menu_model_.AddItem(0, UTF8ToUTF16("Menu For: " + title));
}
......@@ -434,7 +434,7 @@ TEST_F(AppsGridControllerTest, ModelUpdates) {
// Update the title via the ItemModelObserver.
app_list::AppListItemModel* item_model = model()->apps()->GetItemAt(2);
item_model->SetTitle("UpdatedItem");
item_model->SetTitleAndFullName("UpdatedItem", "UpdatedItem");
EXPECT_NSEQ(@"UpdatedItem", [button title]);
EXPECT_EQ(std::string("|Item 0,Item 1,UpdatedItem|"), GetViewContent());
......@@ -467,7 +467,7 @@ TEST_F(AppsGridControllerTest, ModelUpdates) {
EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent());
// Test inserting in the middle.
model()->apps()->AddAt(1, model()->CreateItem("Item One"));
model()->apps()->AddAt(1, model()->CreateItem("Item One", "Item One"));
EXPECT_EQ(3u, [apps_grid_controller_ itemCount]);
EXPECT_EQ(std::string("|Item 0,Item One,Item 2|"), GetViewContent());
......
......@@ -33,14 +33,20 @@ std::string AppListTestModel::GetModelContent() {
return content;
}
AppListItemModel* AppListTestModel::CreateItem(const std::string& title) {
AppListItemModel* AppListTestModel::CreateItem(const std::string& title,
const std::string& full_name) {
AppListItemModel* item = new AppListItemModel;
item->SetTitle(title);
item->SetTitleAndFullName(title, full_name);
return item;
}
void AppListTestModel::AddItem(const std::string& title) {
apps()->Add(CreateItem(title));
apps()->Add(CreateItem(title, title));
}
void AppListTestModel::AddItem(const std::string& title,
const std::string& full_name) {
apps()->Add(CreateItem(title, full_name));
}
void AppListTestModel::HighlightItemAt(int index) {
......
......@@ -29,7 +29,14 @@ class AppListTestModel : public AppListModel {
// Get a string of all apps in |model| joined with ','.
std::string GetModelContent();
AppListItemModel* CreateItem(const std::string& title);
AppListItemModel* CreateItem(const std::string& title,
const std::string& full_name);
// Add an item with arbitrary |title| and |full_name| to the model.
void AddItem(const std::string& title, const std::string& full_name);
// Add an item with arbitrary |title| to the model. This is a convenience
// version which will use the title for the full_name.
void AddItem(const std::string& title);
// Call SetHighlighted on the specified item.
......
......@@ -130,6 +130,11 @@ void AppListItemView::UpdateIcon() {
icon_->SetImage(resized);
}
void AppListItemView::UpdateTooltip() {
title_->SetTooltipText(model_->title() == model_->full_name() ?
string16() : UTF8ToUTF16(model_->full_name()));
}
void AppListItemView::SetUIState(UIState state) {
if (ui_state_ == state)
return;
......@@ -193,6 +198,7 @@ void AppListItemView::ItemIconChanged() {
void AppListItemView::ItemTitleChanged() {
title_->SetText(UTF8ToUTF16(model_->title()));
title_->Invalidate();
UpdateTooltip();
Layout();
}
......
......@@ -62,6 +62,9 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
// Get icon from model and schedule background processing.
void UpdateIcon();
// Update the tooltip text from the model.
void UpdateTooltip();
void SetUIState(UIState state);
// Sets |touch_dragging_| flag and updates UI.
......
......@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/timer/timer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/app_list/app_list_item_model.h"
......@@ -424,5 +425,37 @@ TEST_F(AppsGridViewTest, HighlightWithKeyboard) {
first_index_on_page2)));
}
TEST_F(AppsGridViewTest, ItemLabelShortNameOverride) {
// If the app's full name and short name differ, the title label's tooltip
// should always be the full name of the app.
std::string expected_text("xyz");
std::string expected_tooltip("tooltip");
model_->AddItem(expected_text, expected_tooltip);
string16 actual_tooltip;
AppListItemView* item_view = GetItemViewAt(0);
ASSERT_TRUE(item_view);
const views::Label* title_label = item_view->title();
EXPECT_TRUE(title_label->GetTooltipText(
title_label->bounds().CenterPoint(), &actual_tooltip));
EXPECT_EQ(expected_tooltip, UTF16ToUTF8(actual_tooltip));
EXPECT_EQ(expected_text, UTF16ToUTF8(title_label->text()));
}
TEST_F(AppsGridViewTest, ItemLabelNoShortName) {
// If the app's full name and short name are the same, use the default tooltip
// behavior of the label (only show a tooltip if the title is truncated).
std::string title("a");
model_->AddItem(title, title);
string16 actual_tooltip;
AppListItemView* item_view = GetItemViewAt(0);
ASSERT_TRUE(item_view);
const views::Label* title_label = item_view->title();
EXPECT_FALSE(title_label->GetTooltipText(
title_label->bounds().CenterPoint(), &actual_tooltip));
EXPECT_EQ(title, UTF16ToUTF8(title_label->text()));
}
} // namespace test
} // namespace app_list
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