summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 03:59:44 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 03:59:44 +0000
commitb24740e3b9555bc7b28b602a588a36665882602e (patch)
tree1f5714dc4f932b4707455717d68f1eced18c1052 /chrome/browser/views
parent4831051e6bce5f55c3954bea208c0ce118ea25ff (diff)
downloadchromium_src-b24740e3b9555bc7b28b602a588a36665882602e.zip
chromium_src-b24740e3b9555bc7b28b602a588a36665882602e.tar.gz
chromium_src-b24740e3b9555bc7b28b602a588a36665882602e.tar.bz2
Fixes a handful of related bookmark manager bugs/requests:
. Adds a search field before the text field. . When the search node is selected and there are no results or no search text, a descriptive label is drawn on top of the table telling the user what's happening. . In the bookmark menus Edit... is now Rename... for folders. BUG=5272 5319 5273 4165 TEST=see individual bugs Review URL: http://codereview.chromium.org/13724 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc28
-rw-r--r--chrome/browser/views/bookmark_manager_view.h6
-rw-r--r--chrome/browser/views/bookmark_table_view.cc45
-rw-r--r--chrome/browser/views/bookmark_table_view.h16
4 files changed, 88 insertions, 7 deletions
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index a2071b5..141f57b 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -137,7 +137,7 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile)
tree_view_(NULL),
search_factory_(this) {
search_tf_ = new views::TextField();
- search_tf_->set_default_width_in_chars(40);
+ search_tf_->set_default_width_in_chars(30);
table_view_ = new BookmarkTableView(profile_, NULL);
table_view_->SetObserver(this);
@@ -172,8 +172,11 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile)
column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
0, views::GridLayout::USE_PREF, 0, 0);
column_set->AddPaddingColumn(1, kUnrelatedControlHorizontalSpacing);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
- 1, views::GridLayout::USE_PREF, 0, 0);
+ 0, views::GridLayout::USE_PREF, 0, 0);
column_set->AddPaddingColumn(0, 3); // 3px padding at end of row.
column_set = layout->AddColumnSet(split_cs_id);
@@ -183,6 +186,8 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile)
layout->StartRow(0, top_id);
layout->AddView(organize_menu_button);
layout->AddView(tools_menu_button);
+ layout->AddView(new views::Label(
+ l10n_util::GetString(IDS_BOOKMARK_MANAGER_SEARCH_TITLE)));
layout->AddView(search_tf_);
layout->AddPaddingRow(0, 3); // 3px padding between rows.
@@ -385,6 +390,7 @@ void BookmarkManagerView::OnTreeViewSelectionChanged(
BookmarkTableModel* new_table_model = NULL;
BookmarkNode* table_parent_node = NULL;
+ bool is_search = false;
if (node) {
switch (tree_model_->GetNodeType(node)) {
@@ -402,6 +408,7 @@ void BookmarkManagerView::OnTreeViewSelectionChanged(
break;
case BookmarkFolderTreeModel::SEARCH:
+ is_search = true;
search_factory_.RevokeAll();
new_table_model = CreateSearchTableModel();
break;
@@ -412,7 +419,7 @@ void BookmarkManagerView::OnTreeViewSelectionChanged(
}
}
- SetTableModel(new_table_model, table_parent_node);
+ SetTableModel(new_table_model, table_parent_node, is_search);
}
void BookmarkManagerView::OnTreeViewKeyDown(unsigned short virtual_keycode) {
@@ -540,7 +547,8 @@ BookmarkTableModel* BookmarkManagerView::CreateSearchTableModel() {
}
void BookmarkManagerView::SetTableModel(BookmarkTableModel* new_table_model,
- BookmarkNode* parent_node) {
+ BookmarkNode* parent_node,
+ bool is_search) {
// Be sure and reset the model on the view before updating table_model_.
// Otherwise the view will attempt to use the deleted model when we set the
// new one.
@@ -549,6 +557,16 @@ void BookmarkManagerView::SetTableModel(BookmarkTableModel* new_table_model,
table_view_->SetModel(new_table_model);
table_view_->set_parent_node(parent_node);
table_model_.reset(new_table_model);
+ if (!is_search || (new_table_model && new_table_model->RowCount() > 0)) {
+ table_view_->SetAltText(std::wstring());
+ } else if (search_tf_->GetText().empty()) {
+ table_view_->SetAltText(
+ l10n_util::GetString(IDS_BOOKMARK_MANAGER_NO_SEARCH_TEXT));
+ } else {
+ table_view_->SetAltText(
+ l10n_util::GetStringF(IDS_BOOKMARK_MANAGER_NO_RESULTS,
+ search_tf_->GetText()));
+ }
}
void BookmarkManagerView::PerformSearch() {
@@ -558,7 +576,7 @@ void BookmarkManagerView::PerformSearch() {
tree_view_->SetController(NULL);
tree_view_->SetSelectedNode(tree_model_->search_node());
tree_view_->SetController(this);
- SetTableModel(CreateSearchTableModel(), NULL);
+ SetTableModel(CreateSearchTableModel(), NULL, true);
}
void BookmarkManagerView::PrepareForShow() {
diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h
index 0a4fede..1bcb1c0 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -158,9 +158,11 @@ class BookmarkManagerView : public views::View,
// is no search text.
BookmarkTableModel* CreateSearchTableModel();
- // Sets the model of the table and its parent node.
+ // Sets the model of the table and its parent node. If |is_search| is true,
+ // it means the table is showing search results.
void SetTableModel(BookmarkTableModel* new_table_model,
- BookmarkNode* parent_node);
+ BookmarkNode* parent_node,
+ bool is_search);
// Sets the table's model to the results of CreateSearchTableModel and selects
// the search node in the tree.
diff --git a/chrome/browser/views/bookmark_table_view.cc b/chrome/browser/views/bookmark_table_view.cc
index 33d92df..9241723f 100644
--- a/chrome/browser/views/bookmark_table_view.cc
+++ b/chrome/browser/views/bookmark_table_view.cc
@@ -10,9 +10,12 @@
#include "chrome/browser/bookmarks/bookmark_table_model.h"
#include "chrome/browser/profile.h"
#include "chrome/common/drag_drop_types.h"
+#include "chrome/common/gfx/chrome_canvas.h"
+#include "chrome/common/gfx/chrome_font.h"
#include "chrome/common/os_exchange_data.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "chrome/common/resource_bundle.h"
#include "chrome/views/view_constants.h"
#include "generated_resources.h"
@@ -128,6 +131,18 @@ void BookmarkTableView::SaveColumnConfiguration() {
}
}
+void BookmarkTableView::SetAltText(const std::wstring& alt_text) {
+ if (alt_text == alt_text_)
+ return;
+
+ alt_text_ = alt_text;
+ if (!GetNativeControlHWND())
+ return;
+
+ RECT alt_text_bounds = GetAltTextBounds().ToRECT();
+ InvalidateRect(GetNativeControlHWND(), &alt_text_bounds, FALSE);
+}
+
void BookmarkTableView::SetShowPathColumn(bool show_path_column) {
if (show_path_column == show_path_column_)
return;
@@ -139,6 +154,8 @@ void BookmarkTableView::SetShowPathColumn(bool show_path_column) {
}
void BookmarkTableView::PostPaint() {
+ PaintAltText();
+
if (!drop_info_.get() || drop_info_->position().index == -1 ||
drop_info_->position().on) {
return;
@@ -403,3 +420,31 @@ void BookmarkTableView::UpdateColumns() {
SetColumnVisibility(columns[i].id, true);
OnModelChanged();
}
+
+void BookmarkTableView::PaintAltText() {
+ if (alt_text_.empty())
+ return;
+
+ HDC dc = GetDC(GetNativeControlHWND());
+ ChromeFont font = GetAltTextFont();
+ gfx::Rect bounds = GetAltTextBounds();
+ ChromeCanvas canvas(bounds.width(), bounds.height(), false);
+ canvas.DrawStringInt(alt_text_, font, SK_ColorDKGRAY, 0, 0, bounds.width(),
+ bounds.height());
+ canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL);
+ ReleaseDC(GetNativeControlHWND(), dc);
+}
+
+gfx::Rect BookmarkTableView::GetAltTextBounds() {
+ static const int kXOffset = 16;
+ DCHECK(GetNativeControlHWND());
+ CRect client_rect;
+ GetClientRect(GetNativeControlHWND(), client_rect);
+ ChromeFont font = GetAltTextFont();
+ return gfx::Rect(kXOffset, content_offset(), client_rect.Width() - kXOffset,
+ std::max(kImageSize, font.height()));
+}
+
+ChromeFont BookmarkTableView::GetAltTextFont() {
+ return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
+}
diff --git a/chrome/browser/views/bookmark_table_view.h b/chrome/browser/views/bookmark_table_view.h
index 40dc81e..9568bb4 100644
--- a/chrome/browser/views/bookmark_table_view.h
+++ b/chrome/browser/views/bookmark_table_view.h
@@ -13,6 +13,7 @@
class BookmarkModel;
class BookmarkNode;
class BookmarkTableModel;
+class ChromeFont;
class OSExchangeData;
class PrefService;
class Profile;
@@ -47,6 +48,10 @@ class BookmarkTableView : public views::TableView {
// Saves the widths of the table columns.
void SaveColumnConfiguration();
+ // Sets the text to display on top of the table. This is useful if the table
+ // is empty and you want to inform the user why.
+ void SetAltText(const std::wstring& alt_text);
+
protected:
// Overriden to draw a drop indicator when dropping between rows.
virtual void PostPaint();
@@ -134,6 +139,15 @@ class BookmarkTableView : public views::TableView {
// See ShowPathColumn for details.
void UpdateColumns();
+ // Draws the alt_text_. Does nothing if there is no alt_text_.
+ void PaintAltText();
+
+ // Returns the bounds of the alt text.
+ gfx::Rect GetAltTextBounds();
+
+ // Returns the font used for alt text.
+ ChromeFont GetAltTextFont();
+
Profile* profile_;
BookmarkNode* parent_node_;
@@ -142,6 +156,8 @@ class BookmarkTableView : public views::TableView {
bool show_path_column_;
+ std::wstring alt_text_;
+
DISALLOW_COPY_AND_ASSIGN(BookmarkTableView);
};