summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 18:20:43 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 18:20:43 +0000
commit4b65d2833244db6625daf107e30b75bbd60a4a7b (patch)
tree665de672ded92eb15f7aa7fb50866ddb93a0301d
parent032f25252fbb1d74e2a6ba553f6b87c6ef6e5192 (diff)
downloadchromium_src-4b65d2833244db6625daf107e30b75bbd60a4a7b.zip
chromium_src-4b65d2833244db6625daf107e30b75bbd60a4a7b.tar.gz
chromium_src-4b65d2833244db6625daf107e30b75bbd60a4a7b.tar.bz2
Hide page actions and star, like we already do for content settings, when the user is editing the omnibox.
BUG=none TEST=Typing in the omnibox should make all items on the right disappear, and make ctrl-d do nothing. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58028 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/location_bar/location_bar_view_mac.mm14
-rw-r--r--chrome/browser/cocoa/location_bar/page_action_decoration.mm21
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc35
-rw-r--r--chrome/browser/views/location_bar/location_bar_view.cc14
-rw-r--r--chrome/browser/views/location_bar/page_action_image_view.cc71
5 files changed, 85 insertions, 70 deletions
diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
index 28f524b..9bc4d1d 100644
--- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
@@ -33,6 +33,7 @@
#include "chrome/browser/command_updater.h"
#include "chrome/browser/content_setting_image_model.h"
#include "chrome/browser/content_setting_bubble_model.h"
+#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
@@ -183,6 +184,10 @@ void LocationBarViewMac::SaveStateToContents(TabContents* contents) {
void LocationBarViewMac::Update(const TabContents* contents,
bool should_restore_state) {
+ bool star_enabled = browser_defaults::bookmarks_enabled &&
+ [field_ isEditable] && !toolbar_model_->input_in_progress();
+ command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
+ star_decoration_->SetVisible(star_enabled);
RefreshPageActionDecorations();
RefreshContentSettingsDecorations();
// AutocompleteEditView restores state if the tab is non-NULL.
@@ -371,7 +376,8 @@ void LocationBarViewMac::TestPageActionPressed(size_t index) {
void LocationBarViewMac::SetEditable(bool editable) {
[field_ setEditable:editable ? YES : NO];
- star_decoration_->SetVisible(editable);
+ star_decoration_->SetVisible(browser_defaults::bookmarks_enabled &&
+ editable && !toolbar_model_->input_in_progress());
UpdatePageActions();
Layout();
}
@@ -490,8 +496,10 @@ void LocationBarViewMac::RefreshPageActionDecorations() {
return;
GURL url = GURL(WideToUTF8(toolbar_model_->GetText()));
- for (size_t i = 0; i < page_action_decorations_.size(); ++i)
- page_action_decorations_[i]->UpdateVisibility(contents, url);
+ for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
+ page_action_decorations_[i]->UpdateVisibility(
+ toolbar_model_->input_in_progress() ? NULL : contents, url);
+ }
}
// TODO(shess): This function should over time grow to closely match
diff --git a/chrome/browser/cocoa/location_bar/page_action_decoration.mm b/chrome/browser/cocoa/location_bar/page_action_decoration.mm
index d306d87..337cd2f 100644
--- a/chrome/browser/cocoa/location_bar/page_action_decoration.mm
+++ b/chrome/browser/cocoa/location_bar/page_action_decoration.mm
@@ -121,15 +121,15 @@ void PageActionDecoration::OnImageLoaded(
owner_->UpdatePageActions();
}
-void PageActionDecoration::UpdateVisibility(
- TabContents* contents, const GURL& url) {
+void PageActionDecoration::UpdateVisibility(TabContents* contents,
+ const GURL& url) {
// Save this off so we can pass it back to the extension when the action gets
// executed. See PageActionDecoration::OnMousePressed.
- current_tab_id_ = ExtensionTabUtil::GetTabId(contents);
+ current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1;
current_url_ = url;
- bool visible = preview_enabled_ ||
- page_action_->GetIsVisible(current_tab_id_);
+ bool visible = contents &&
+ (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_));
if (visible) {
SetToolTip(page_action_->GetTitle(current_tab_id_));
@@ -146,19 +146,15 @@ void PageActionDecoration::UpdateVisibility(
SkBitmap skia_icon = page_action_->GetIcon(current_tab_id_);
if (skia_icon.isNull()) {
int icon_index = page_action_->GetIconIndex(current_tab_id_);
- std::string icon_path;
- if (icon_index >= 0)
- icon_path = page_action_->icon_paths()->at(icon_index);
- else
- icon_path = page_action_->default_icon_path();
-
+ std::string icon_path = (icon_index < 0) ?
+ page_action_->default_icon_path() :
+ page_action_->icon_paths()->at(icon_index);
if (!icon_path.empty()) {
PageActionMap::iterator iter = page_action_icons_.find(icon_path);
if (iter != page_action_icons_.end())
skia_icon = iter->second;
}
}
-
if (!skia_icon.isNull()) {
SetImage(gfx::SkBitmapToNSImage(skia_icon));
} else if (!GetImage()) {
@@ -171,6 +167,7 @@ void PageActionDecoration::UpdateVisibility(
SetImage([[NSImage alloc] initWithSize:default_size]);
}
}
+
if (IsVisible() != visible) {
SetVisible(visible);
NotificationService::current()->Notify(
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 95b1bbb..705be84 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -257,7 +257,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
gtk_box_pack_end(GTK_BOX(entry_box_), tab_to_search_hint_, FALSE, FALSE, 0);
// We don't show the star in popups, app windows, etc.
- if (!ShouldOnlyShowLocation()) {
+ if (browser_defaults::bookmarks_enabled && !ShouldOnlyShowLocation()) {
CreateStarButton();
gtk_box_pack_end(GTK_BOX(hbox_.get()), star_.get(), FALSE, FALSE, 0);
}
@@ -407,6 +407,14 @@ GtkWidget* LocationBarViewGtk::GetPageActionWidget(
}
void LocationBarViewGtk::Update(const TabContents* contents) {
+ bool star_enabled = star_.get() && !toolbar_model_->input_in_progress();
+ command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
+ if (star_.get()) {
+ if (star_enabled)
+ gtk_widget_show_all(star_.get());
+ else
+ gtk_widget_hide_all(star_.get());
+ }
UpdateSiteTypeArea();
UpdateContentSettingsIcons();
UpdatePageActions();
@@ -615,8 +623,10 @@ void LocationBarViewGtk::UpdatePageActions() {
if (!page_action_views_.empty() && contents) {
GURL url = GURL(WideToUTF8(toolbar_model_->GetText()));
- for (size_t i = 0; i < page_action_views_.size(); i++)
- page_action_views_[i]->UpdateVisibility(contents, url);
+ for (size_t i = 0; i < page_action_views_.size(); i++) {
+ page_action_views_[i]->UpdateVisibility(
+ toolbar_model_->input_in_progress() ? NULL : contents, url);
+ }
}
// If there are no visible page actions, hide the hbox too, so that it does
@@ -1268,15 +1278,14 @@ void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility(
TabContents* contents, GURL url) {
// Save this off so we can pass it back to the extension when the action gets
// executed. See PageActionImageView::OnMousePressed.
- current_tab_id_ = ExtensionTabUtil::GetTabId(contents);
+ current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1;
current_url_ = url;
- bool visible = preview_enabled_ ||
- page_action_->GetIsVisible(current_tab_id_);
+ bool visible = contents &&
+ (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_));
if (visible) {
// Set the tooltip.
- gtk_widget_set_tooltip_text(
- event_box_.get(),
+ gtk_widget_set_tooltip_text(event_box_.get(),
page_action_->GetTitle(current_tab_id_).c_str());
// Set the image.
@@ -1304,19 +1313,15 @@ void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility(
// Otherwise look for a dynamically set index, or fall back to the
// default path.
int icon_index = page_action_->GetIconIndex(current_tab_id_);
- std::string icon_path;
- if (icon_index >= 0)
- icon_path = page_action_->icon_paths()->at(icon_index);
- else
- icon_path = page_action_->default_icon_path();
-
+ std::string icon_path = (icon_index < 0) ?
+ page_action_->default_icon_path() :
+ page_action_->icon_paths()->at(icon_index);
if (!icon_path.empty()) {
PixbufMap::iterator iter = pixbufs_.find(icon_path);
if (iter != pixbufs_.end())
pixbuf = iter->second;
}
}
-
// The pixbuf might not be loaded yet.
if (pixbuf)
gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf);
diff --git a/chrome/browser/views/location_bar/location_bar_view.cc b/chrome/browser/views/location_bar/location_bar_view.cc
index 057e23e..fdfdacc 100644
--- a/chrome/browser/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/views/location_bar/location_bar_view.cc
@@ -15,6 +15,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/alternate_nav_url_fetcher.h"
+#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/profile.h"
@@ -189,7 +190,7 @@ void LocationBarView::Init() {
}
// The star is not visible in popups and in the app launcher.
- if (mode_ == NORMAL) {
+ if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
star_view_ = new StarView(command_updater_);
AddChildView(star_view_);
star_view_->SetVisible(true);
@@ -260,6 +261,10 @@ SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level,
}
void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
+ bool star_enabled = star_view_ && !model_->input_in_progress();
+ command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
+ if (star_view_)
+ star_view_->SetVisible(star_enabled);
RefreshContentSettingViews();
RefreshPageActionViews();
// Don't Update in app launcher mode so that the location entry does not show
@@ -429,7 +434,7 @@ void LocationBarView::Layout() {
kItemEditPadding);
}
- if (star_view_)
+ if (star_view_ && star_view_->IsVisible())
entry_width -= star_view_->GetPreferredSize().width() + kItemPadding;
for (PageActionViews::const_iterator i(page_action_views_.begin());
i != page_action_views_.end(); ++i) {
@@ -497,7 +502,7 @@ void LocationBarView::Layout() {
// Lay out items to the right of the edit field.
int offset = width() - kEdgeThickness - kEdgeItemPadding;
- if (star_view_) {
+ if (star_view_ && star_view_->IsVisible()) {
int star_width = star_view_->GetPreferredSize().width();
offset -= star_width;
star_view_->SetBounds(offset, location_y, star_width, location_height);
@@ -841,7 +846,8 @@ void LocationBarView::RefreshPageActionViews() {
for (PageActionViews::const_iterator i(page_action_views_.begin());
i != page_action_views_.end(); ++i) {
- (*i)->UpdateVisibility(contents, url);
+ (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents,
+ url);
// Check if the visibility of the action changed and notify if it did.
ExtensionAction* action = (*i)->image_view()->page_action();
diff --git a/chrome/browser/views/location_bar/page_action_image_view.cc b/chrome/browser/views/location_bar/page_action_image_view.cc
index 0f6358b..c2d72e3 100644
--- a/chrome/browser/views/location_bar/page_action_image_view.cc
+++ b/chrome/browser/views/location_bar/page_action_image_view.cc
@@ -182,46 +182,45 @@ void PageActionImageView::UpdateVisibility(TabContents* contents,
const GURL& url) {
// Save this off so we can pass it back to the extension when the action gets
// executed. See PageActionImageView::OnMousePressed.
- current_tab_id_ = ExtensionTabUtil::GetTabId(contents);
+ current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1;
current_url_ = url;
- bool visible =
- preview_enabled_ || page_action_->GetIsVisible(current_tab_id_);
- if (visible) {
- // Set the tooltip.
- tooltip_ = page_action_->GetTitle(current_tab_id_);
- SetTooltipText(UTF8ToWide(tooltip_));
-
- // Set the image.
- // It can come from three places. In descending order of priority:
- // - The developer can set it dynamically by path or bitmap. It will be in
- // page_action_->GetIcon().
- // - The developer can set it dynamically by index. It will be in
- // page_action_->GetIconIndex().
- // - It can be set in the manifest by path. It will be in page_action_->
- // default_icon_path().
-
- // First look for a dynamically set bitmap.
- SkBitmap icon = page_action_->GetIcon(current_tab_id_);
- if (icon.isNull()) {
- int icon_index = page_action_->GetIconIndex(current_tab_id_);
- std::string icon_path;
- if (icon_index >= 0)
- icon_path = page_action_->icon_paths()->at(icon_index);
- else
- icon_path = page_action_->default_icon_path();
-
- if (!icon_path.empty()) {
- PageActionMap::iterator iter = page_action_icons_.find(icon_path);
- if (iter != page_action_icons_.end())
- icon = iter->second;
- }
- }
+ if (!contents ||
+ (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
+ SetVisible(false);
+ return;
+ }
- if (!icon.isNull())
- SetImage(&icon);
+ // Set the tooltip.
+ tooltip_ = page_action_->GetTitle(current_tab_id_);
+ SetTooltipText(UTF8ToWide(tooltip_));
+
+ // Set the image.
+ // It can come from three places. In descending order of priority:
+ // - The developer can set it dynamically by path or bitmap. It will be in
+ // page_action_->GetIcon().
+ // - The developer can set it dynamically by index. It will be in
+ // page_action_->GetIconIndex().
+ // - It can be set in the manifest by path. It will be in
+ // page_action_->default_icon_path().
+
+ // First look for a dynamically set bitmap.
+ SkBitmap icon = page_action_->GetIcon(current_tab_id_);
+ if (icon.isNull()) {
+ int icon_index = page_action_->GetIconIndex(current_tab_id_);
+ std::string icon_path = (icon_index < 0) ?
+ page_action_->default_icon_path() :
+ page_action_->icon_paths()->at(icon_index);
+ if (!icon_path.empty()) {
+ PageActionMap::iterator iter = page_action_icons_.find(icon_path);
+ if (iter != page_action_icons_.end())
+ icon = iter->second;
+ }
}
- SetVisible(visible);
+ if (!icon.isNull())
+ SetImage(&icon);
+
+ SetVisible(true);
}
void PageActionImageView::InspectPopup(ExtensionAction* action) {