diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-13 17:03:07 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-13 17:03:07 +0000 |
commit | 38c0e99c382e4bf5ba04720f207338dba103f67f (patch) | |
tree | 6919b371afc1c5141388a90f8d09d6e199b9d0d3 /chrome/browser/views | |
parent | 1540cd50af4875ae49a4012015bac43ae17c2258 (diff) | |
download | chromium_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')
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 218 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 79 |
2 files changed, 222 insertions, 75 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( diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index 07b9e06..99822f4 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -120,6 +120,7 @@ class LocationBarView : public LocationBar, virtual void AcceptInput(); virtual void FocusLocation(); virtual void FocusSearch(); + virtual void UpdateFeedIcon(); virtual void SaveStateToContents(TabContents* contents); static const int kVertMargin; @@ -224,13 +225,45 @@ class LocationBarView : public LocationBar, class ShowInfoBubbleTask; class ShowFirstRunBubbleTask; + class LocationBarImageView : public views::ImageView, + public InfoBubbleDelegate { + public: + LocationBarImageView(); + virtual ~LocationBarImageView(); + + // Overridden from view for the mouse hovering. + virtual void OnMouseMoved(const views::MouseEvent& event); + virtual void OnMouseExited(const views::MouseEvent& event); + virtual bool OnMousePressed(const views::MouseEvent& event) = 0; + + // InfoBubbleDelegate + void InfoBubbleClosing(InfoBubble* info_bubble, bool closed_by_escape); + bool CloseOnEscape() { return true; } + + virtual void ShowInfoBubble() = 0; + + protected: + void ShowInfoBubbleImpl(const std::wstring& text, SkColor text_color); + + private: + friend class ShowInfoBubbleTask; + + // The currently shown info bubble if any. + InfoBubble* info_bubble_; + + // A task used to display the info bubble when the mouse hovers on the + // image. + ShowInfoBubbleTask* show_info_bubble_task_; + + DISALLOW_COPY_AND_ASSIGN(LocationBarImageView); + }; + // SecurityImageView is used to display the lock or warning icon when the // current URL's scheme is https. // // If a message has been set with SetInfoBubbleText, it displays an info // bubble when the mouse hovers on the image. - class SecurityImageView : public views::ImageView, - public InfoBubbleDelegate { + class SecurityImageView : public LocationBarImageView { public: enum Image { LOCK = 0, @@ -244,21 +277,13 @@ class LocationBarView : public LocationBar, void SetImageShown(Image image); // Overridden from view for the mouse hovering. - virtual void OnMouseMoved(const views::MouseEvent& event); - virtual void OnMouseExited(const views::MouseEvent& event); virtual bool OnMousePressed(const views::MouseEvent& event); - // InfoBubbleDelegate - void InfoBubbleClosing(InfoBubble* info_bubble, bool closed_by_escape); - bool CloseOnEscape() { return true; } - void set_profile(Profile* profile) { profile_ = profile; } - private: - friend class ShowInfoBubbleTask; - - void ShowInfoBubble(); + virtual void ShowInfoBubble(); + private: // The lock icon shown when using HTTPS. static SkBitmap* lock_icon_; @@ -279,6 +304,30 @@ class LocationBarView : public LocationBar, DISALLOW_EVIL_CONSTRUCTORS(SecurityImageView); }; + // RssImageView is used to display the RSS icon when the page has a feed that + // you can subscribe to. + // + // If a message has been set with SetInfoBubbleText, it displays an info + // bubble when the mouse hovers on the image. + class RssImageView : public LocationBarImageView { + public: + explicit RssImageView(ToolbarModel* model); + virtual ~RssImageView(); + + // Overridden from view for the mouse hovering. + virtual bool OnMousePressed(const views::MouseEvent& event); + + virtual void ShowInfoBubble(); + + private: + // The RSS icon shown when page has a feed. + static SkBitmap* rss_icon_; + + ToolbarModel* model_; + + DISALLOW_COPY_AND_ASSIGN(RssImageView); + }; + // Both Layout and OnChanged call into this. This updates the contents // of the 3 views: selected_keyword, keyword_hint and type_search_view. If // force_layout is true, or one of these views has changed in such a way as @@ -316,6 +365,9 @@ class LocationBarView : public LocationBar, // Sets the security icon to display. Note that no repaint is done. void SetSecurityIcon(ToolbarModel::Icon icon); + // Sets the RSS icon visibility. + void SetRssIconVisibility(FeedList* feeds); + // Sets the text that should be displayed in the info label and its associated // tooltip text. Call with an empty string if the info label should be // hidden. @@ -381,6 +433,9 @@ class LocationBarView : public LocationBar, // The view that shows the lock/warning when in HTTPS mode. SecurityImageView security_image_view_; + // The view that shows the RSS icon when the page has an RSS feed. + RssImageView rss_image_view_; + // A label displayed after the lock icon to show some extra information. views::Label info_label_; |