summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/location_bar_view.cc
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-13 17:03:07 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-13 17:03:07 +0000
commit38c0e99c382e4bf5ba04720f207338dba103f67f (patch)
tree6919b371afc1c5141388a90f8d09d6e199b9d0d3 /chrome/browser/views/location_bar_view.cc
parent1540cd50af4875ae49a4012015bac43ae17c2258 (diff)
downloadchromium_src-38c0e99c382e4bf5ba04720f207338dba103f67f.zip
chromium_src-38c0e99c382e4bf5ba04720f207338dba103f67f.tar.gz
chromium_src-38c0e99c382e4bf5ba04720f207338dba103f67f.tar.bz2
RSS feed support (part 1)
Part 1 is RSS feed auto-discovery. This will parse the web page header to find the feeds in the document and notify the browser to display the RSS icon in the toolbar. You can click on the icon, but it will just navigate to the first feed on the page, which (unless it has been designed to be browser friendly) will just dump XML as text on the user. For this reason I have disabled the code that makes the RSS icon appear and intend to enable it when we have a good landing page to display the XML. Review URL: http://codereview.chromium.org/43109 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/location_bar_view.cc')
-rw-r--r--chrome/browser/views/location_bar_view.cc218
1 files changed, 155 insertions, 63 deletions
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 0596974..d759fc0 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -91,6 +91,7 @@ LocationBarView::LocationBarView(Profile* profile,
keyword_hint_view_(profile),
type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)),
security_image_view_(profile, model),
+ rss_image_view_(model),
popup_window_mode_(popup_window_mode),
first_run_bubble_(this) {
DCHECK(profile_);
@@ -153,6 +154,10 @@ void LocationBarView::Init() {
keyword_hint_view_.SetColor(gray);
keyword_hint_view_.SetParentOwned(false);
+ AddChildView(&rss_image_view_);
+ rss_image_view_.SetVisible(false);
+ rss_image_view_.SetParentOwned(false);
+
AddChildView(&security_image_view_);
security_image_view_.SetVisible(false);
security_image_view_.SetParentOwned(false);
@@ -174,6 +179,7 @@ void LocationBarView::Init() {
void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
SetSecurityIcon(model_->GetIcon());
+ SetRssIconVisibility(model_->GetFeedList().get());
std::wstring info_text, info_tooltip;
SkColor text_color;
model_->GetInfoText(&info_text, &text_color, &info_tooltip);
@@ -183,6 +189,12 @@ void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
SchedulePaint();
}
+void LocationBarView::UpdateFeedIcon() {
+ SetRssIconVisibility(model_->GetFeedList().get());
+ Layout();
+ SchedulePaint();
+}
+
void LocationBarView::Focus() {
::SetFocus(location_entry_->m_hWnd);
}
@@ -335,10 +347,16 @@ void LocationBarView::DoLayout(const bool force_layout) {
location_entry_->GetClientRect(&edit_bounds);
int entry_width = width() - (kEntryPadding * 2);
+
+ gfx::Size rss_image_size;
+ if (rss_image_view_.IsVisible()) {
+ rss_image_size = rss_image_view_.GetPreferredSize();
+ entry_width -= rss_image_size.width();
+ }
gfx::Size security_image_size;
if (security_image_view_.IsVisible()) {
security_image_size = security_image_view_.GetPreferredSize();
- entry_width -= security_image_size.width();
+ entry_width -= security_image_size.width() + kInnerPadding;
}
gfx::Size info_label_size;
if (info_label_.IsVisible()) {
@@ -365,9 +383,18 @@ void LocationBarView::DoLayout(const bool force_layout) {
location_y,
info_label_size.width(), location_height);
}
+ const int info_label_width = info_label_size.width() ?
+ info_label_size.width() + kInnerPadding : 0;
+ if (rss_image_view_.IsVisible()) {
+ rss_image_view_.SetBounds(width() - kEntryPadding -
+ info_label_width -
+ security_image_size.width() -
+ rss_image_size.width(),
+ location_y,
+ rss_image_size.width(),
+ location_height);
+ }
if (security_image_view_.IsVisible()) {
- const int info_label_width = info_label_size.width() ?
- info_label_size.width() + kInnerPadding : 0;
security_image_view_.SetBounds(width() - kEntryPadding - info_label_width -
security_image_size.width(), location_y, security_image_size.width(),
location_height);
@@ -498,6 +525,12 @@ void LocationBarView::SetSecurityIcon(ToolbarModel::Icon icon) {
}
}
+void LocationBarView::SetRssIconVisibility(FeedList* feeds) {
+ bool show_rss = feeds && feeds->list().size() > 0;
+ // TODO(finnur): Enable this when we have a good landing page to show feeds.
+ rss_image_view_.SetVisible(false);
+}
+
void LocationBarView::SetInfoText(const std::wstring& text,
SkColor text_color,
const std::wstring& tooltip_text) {
@@ -771,19 +804,20 @@ bool LocationBarView::ShouldLookupAccelerators(const views::KeyEvent& e) {
class LocationBarView::ShowInfoBubbleTask : public Task {
public:
- explicit ShowInfoBubbleTask(LocationBarView::SecurityImageView* image_view);
+ explicit ShowInfoBubbleTask(
+ LocationBarView::LocationBarImageView* image_view);
virtual void Run();
void Cancel();
private:
- LocationBarView::SecurityImageView* image_view_;
+ LocationBarView::LocationBarImageView* image_view_;
bool cancelled_;
DISALLOW_EVIL_CONSTRUCTORS(ShowInfoBubbleTask);
};
LocationBarView::ShowInfoBubbleTask::ShowInfoBubbleTask(
- LocationBarView::SecurityImageView* image_view)
+ LocationBarView::LocationBarImageView* image_view)
: cancelled_(false),
image_view_(image_view) {
}
@@ -842,27 +876,14 @@ void LocationBarView::ShowFirstRunBubbleInternal() {
bounds);
}
-// SecurityImageView------------------------------------------------------------
-
-// static
-SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL;
-SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL;
+// LocationBarImageView---------------------------------------------------------
-LocationBarView::SecurityImageView::SecurityImageView(Profile* profile,
- ToolbarModel* model)
- : profile_(profile),
- model_(model),
- show_info_bubble_task_(NULL),
- info_bubble_(NULL) {
- if (!lock_icon_) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- lock_icon_ = rb.GetBitmapNamed(IDR_LOCK);
- warning_icon_ = rb.GetBitmapNamed(IDR_WARNING);
- }
- SetImageShown(LOCK);
+LocationBarView::LocationBarImageView::LocationBarImageView()
+ : show_info_bubble_task_(NULL),
+ info_bubble_(NULL) {
}
-LocationBarView::SecurityImageView::~SecurityImageView() {
+LocationBarView::LocationBarImageView::~LocationBarImageView() {
if (show_info_bubble_task_)
show_info_bubble_task_->Cancel();
@@ -873,25 +894,41 @@ LocationBarView::SecurityImageView::~SecurityImageView() {
}
}
-void LocationBarView::SecurityImageView::SetImageShown(Image image) {
- switch (image) {
- case LOCK:
- ImageView::SetImage(lock_icon_);
- break;
- case WARNING:
- ImageView::SetImage(warning_icon_);
- break;
- default:
- NOTREACHED();
- break;
+void LocationBarView::LocationBarImageView::OnMouseMoved(
+ const views::MouseEvent& event) {
+ if (show_info_bubble_task_) {
+ show_info_bubble_task_->Cancel();
+ show_info_bubble_task_ = NULL;
}
+
+ if (info_bubble_) {
+ // If an info bubble is currently showing, nothing to do.
+ return;
+ }
+
+ show_info_bubble_task_ = new ShowInfoBubbleTask(this);
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, show_info_bubble_task_,
+ kInfoBubbleHoverDelayMs);
}
-void LocationBarView::SecurityImageView::ShowInfoBubble() {
- std::wstring text;
- SkColor text_color;
- model_->GetIconHoverText(&text, &text_color);
+void LocationBarView::LocationBarImageView::OnMouseExited(
+ const views::MouseEvent& event) {
+ if (show_info_bubble_task_) {
+ show_info_bubble_task_->Cancel();
+ show_info_bubble_task_ = NULL;
+ }
+
+ if (info_bubble_)
+ info_bubble_->Close();
+}
+
+void LocationBarView::LocationBarImageView::InfoBubbleClosing(
+ InfoBubble* info_bubble, bool closed_by_escape) {
+ info_bubble_ = NULL;
+}
+void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl(
+ const std::wstring& text, SkColor text_color) {
gfx::Point location;
views::View::ConvertPointToScreen(this, &location);
gfx::Rect bounds(location.x(), location.y(), width(), height());
@@ -909,32 +946,40 @@ void LocationBarView::SecurityImageView::ShowInfoBubble() {
show_info_bubble_task_ = NULL;
}
-void LocationBarView::SecurityImageView::OnMouseMoved(
- const views::MouseEvent& event) {
- if (show_info_bubble_task_) {
- show_info_bubble_task_->Cancel();
- show_info_bubble_task_ = NULL;
- }
+// SecurityImageView------------------------------------------------------------
- if (info_bubble_) {
- // If an info bubble is currently showing, nothing to do.
- return;
+// static
+SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL;
+SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL;
+
+LocationBarView::SecurityImageView::SecurityImageView(Profile* profile,
+ ToolbarModel* model)
+ : LocationBarImageView(),
+ profile_(profile),
+ model_(model) {
+ if (!lock_icon_) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ lock_icon_ = rb.GetBitmapNamed(IDR_LOCK);
+ warning_icon_ = rb.GetBitmapNamed(IDR_WARNING);
}
+ SetImageShown(LOCK);
+}
- show_info_bubble_task_ = new ShowInfoBubbleTask(this);
- MessageLoop::current()->PostDelayedTask(FROM_HERE, show_info_bubble_task_,
- kInfoBubbleHoverDelayMs);
+LocationBarView::SecurityImageView::~SecurityImageView() {
}
-void LocationBarView::SecurityImageView::OnMouseExited(
- const views::MouseEvent& event) {
- if (show_info_bubble_task_) {
- show_info_bubble_task_->Cancel();
- show_info_bubble_task_ = NULL;
+void LocationBarView::SecurityImageView::SetImageShown(Image image) {
+ switch (image) {
+ case LOCK:
+ ImageView::SetImage(lock_icon_);
+ break;
+ case WARNING:
+ ImageView::SetImage(warning_icon_);
+ break;
+ default:
+ NOTREACHED();
+ break;
}
-
- if (info_bubble_)
- info_bubble_->Close();
}
bool LocationBarView::SecurityImageView::OnMousePressed(
@@ -953,10 +998,57 @@ bool LocationBarView::SecurityImageView::OnMousePressed(
return true;
}
-void LocationBarView::SecurityImageView::InfoBubbleClosing(
- InfoBubble* info_bubble,
- bool closed_by_escape) {
- info_bubble_ = NULL;
+void LocationBarView::SecurityImageView::ShowInfoBubble() {
+ std::wstring text;
+ SkColor text_color;
+ model_->GetIconHoverText(&text, &text_color);
+
+ ShowInfoBubbleImpl(text, text_color);
+}
+
+// RssImageView------------------------------------------------------------
+
+// static
+SkBitmap* LocationBarView::RssImageView::rss_icon_ = NULL;
+
+LocationBarView::RssImageView::RssImageView(ToolbarModel* model)
+ : model_(model),
+ LocationBarImageView() {
+ if (!rss_icon_) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ rss_icon_ = rb.GetBitmapNamed(IDR_RSS_ICON);
+ }
+ ImageView::SetImage(rss_icon_);
+}
+
+LocationBarView::RssImageView::~RssImageView() {
+}
+
+bool LocationBarView::RssImageView::OnMousePressed(
+ const views::MouseEvent& event) {
+ NavigationEntry* entry =
+ BrowserList::GetLastActive()->GetSelectedTabContents()->
+ controller()->GetActiveEntry();
+ if (!entry) {
+ NOTREACHED();
+ return true;
+ }
+
+ // Navigate to the first item in the feed list.
+ scoped_refptr<FeedList> feeds = model_->GetFeedList();
+ DCHECK(feeds.get() && feeds->list().size() > 0);
+
+ // TODO(finnur): Make this do more than just display the XML in the browser.
+ BrowserList::GetLastActive()->OpenURL(feeds->list()[0].url, GURL(),
+ CURRENT_TAB, PageTransition::LINK);
+ return true;
+}
+
+void LocationBarView::RssImageView::ShowInfoBubble() {
+ // TODO(finnur): Get this string from the resources.
+ std::wstring text = L"Subscribe to this feed";
+ SkColor text_color = SK_ColorBLUE;
+ ShowInfoBubbleImpl(text, text_color);
}
bool LocationBarView::OverrideAccelerator(