From 606397473431bf7d5effa5bbfce7c224f652346b Mon Sep 17 00:00:00 2001 From: stippi Date: Mon, 1 Mar 2010 18:46:15 +0000 Subject: [PATCH] Finished all the wiring necessary for favicon support. Send the NAVIGATION_REQUESTED notification again from the FrameLoaderClient, this way we can try to fetch the icon even earlier. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@259 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserWindow.cpp | 3 +- src/apps/webpositive/WebTabView.cpp | 91 +++++++++++++++++++++++--- src/apps/webpositive/WebTabView.h | 9 ++- 3 files changed, 91 insertions(+), 12 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index c72925f889..0e811e4c8d 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -321,6 +321,7 @@ BrowserWindow::MessageReceived(BMessage* message) BString url; if (message->FindString("url", &url) != B_OK) url = fURLTextControl->Text(); + fTabManager->SetTabIcon(CurrentWebView(), NULL); CurrentWebView()->LoadURL(url.String()); break; } @@ -703,7 +704,7 @@ BrowserWindow::TitleChanged(const BString& title, BWebView* view) void BrowserWindow::IconReceived(const BBitmap* icon, BWebView* view) { - printf("BrowserWindow::IconReceived(%p, %p)\n", icon, view); + fTabManager->SetTabIcon(view, icon); } diff --git a/src/apps/webpositive/WebTabView.cpp b/src/apps/webpositive/WebTabView.cpp index a4e073dc40..bdbeb85c0b 100644 --- a/src/apps/webpositive/WebTabView.cpp +++ b/src/apps/webpositive/WebTabView.cpp @@ -31,6 +31,7 @@ #include "WebView.h" #include #include +#include #include #include #include @@ -146,6 +147,7 @@ public: void AddTab(const char* label, int32 index = -1); void AddTab(TabView* tab, int32 index = -1); TabView* RemoveTab(int32 index); + TabView* TabAt(int32 index) const; int32 IndexOf(TabView* tab) const; @@ -382,6 +384,17 @@ TabContainerView::RemoveTab(int32 index) } +TabView* +TabContainerView::TabAt(int32 index) const +{ + TabLayoutItem* item = dynamic_cast( + GroupLayout()->ItemAt(index)); + if (item) + return item->Parent(); + return NULL; +} + + int32 TabContainerView::IndexOf(TabView* tab) const { @@ -738,6 +751,7 @@ private: class WebTabView : public TabView { public: WebTabView(TabManagerController* controller); + ~WebTabView(); virtual BSize MaxSize(); @@ -749,12 +763,15 @@ public: virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); + void SetIcon(const BBitmap* icon); + private: void _DrawCloseButton(BView* owner, BRect& frame, const BRect& updateRect, bool isFirst, bool isLast, bool isFront); BRect _CloseRectFrame(BRect frame) const; private: + BBitmap* fIcon; TabManagerController* fController; bool fOverCloseRect; bool fClicked; @@ -764,6 +781,7 @@ private: WebTabView::WebTabView(TabManagerController* controller) : TabView(), + fIcon(NULL), fController(controller), fOverCloseRect(false), fClicked(false) @@ -771,11 +789,21 @@ WebTabView::WebTabView(TabManagerController* controller) } +WebTabView::~WebTabView() +{ + delete fIcon; +} + + BSize WebTabView::MaxSize() { - // Account for close button. + // Account for icon. BSize size(TabView::MaxSize()); + size.height = max_c(size.height, 16 + 8); + if (fIcon) + size.width += 16 + 8; + // Account for close button. size.width += size.height; return size; } @@ -788,6 +816,19 @@ WebTabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect, if (fController->CloseButtonsAvailable()) _DrawCloseButton(owner, frame, updateRect, isFirst, isLast, isFront); + if (fIcon) { + BRect iconBounds(0, 0, 15, 15); + // clip to icon bounds, if they are smaller + if (iconBounds.Contains(fIcon->Bounds())) + iconBounds = fIcon->Bounds(); + BPoint iconPos(frame.left + 4, + frame.top + (frame.Height() - iconBounds.Height()) / 2); + iconBounds.OffsetTo(iconPos); + owner->SetDrawingMode(B_OP_OVER); + owner->DrawBitmap(fIcon, fIcon->Bounds(), iconBounds); + frame.left = frame.left + 16 + 8; + } + TabView::DrawContents(owner, frame, updateRect, isFirst, isLast, isFront); } @@ -843,6 +884,18 @@ WebTabView::MouseMoved(BPoint where, uint32 transit, } +void +WebTabView::SetIcon(const BBitmap* icon) +{ + delete fIcon; + if (icon) + fIcon = new BBitmap(icon); + else + fIcon = NULL; + LayoutItem()->InvalidateLayout(); +} + + BRect WebTabView::_CloseRectFrame(BRect frame) const { @@ -1181,16 +1234,11 @@ TabManager::SelectTab(int32 tabIndex) void -TabManager::SelectTab(BView* containedView) +TabManager::SelectTab(const BView* containedView) { - int32 count = fCardLayout->CountItems(); - for (int32 i = 0; i < count; i++) { - BLayoutItem* item = fCardLayout->ItemAt(i); - if (item->View() == containedView) { - SelectTab(i); - break; - } - } + int32 tabIndex = _TabIndexForContainedView(containedView); + if (tabIndex > 0) + SelectTab(tabIndex); } @@ -1252,6 +1300,16 @@ TabManager::SetTabLabel(int32 tabIndex, const char* label) } +void +TabManager::SetTabIcon(const BView* containedView, const BBitmap* icon) +{ + WebTabView* tab = dynamic_cast(fTabContainerView->TabAt( + _TabIndexForContainedView(containedView))); + if (tab) + tab->SetIcon(icon); +} + + void TabManager::SetCloseButtonsAvailable(bool available) { @@ -1261,3 +1319,16 @@ TabManager::SetCloseButtonsAvailable(bool available) fTabContainerView->Invalidate(); } + +int32 +TabManager::_TabIndexForContainedView(const BView* containedView) const +{ + int32 count = fCardLayout->CountItems(); + for (int32 i = 0; i < count; i++) { + BLayoutItem* item = fCardLayout->ItemAt(i); + if (item->View() == containedView) + return i; + } + return -1; +} + diff --git a/src/apps/webpositive/WebTabView.h b/src/apps/webpositive/WebTabView.h index 69d7a032d9..93129b1b0c 100644 --- a/src/apps/webpositive/WebTabView.h +++ b/src/apps/webpositive/WebTabView.h @@ -36,6 +36,7 @@ enum { CLOSE_TAB = 'cltb' }; +class BBitmap; class BCardLayout; class BGroupView; class BMenu; @@ -61,7 +62,7 @@ public: BView* ViewForTab(int32 tabIndex) const; void SelectTab(int32 tabIndex); - void SelectTab(BView* containedView); + void SelectTab(const BView* containedView); int32 SelectedTabIndex() const; void CloseTab(int32 tabIndex); @@ -71,8 +72,14 @@ public: int32 CountTabs() const; void SetTabLabel(int32 tabIndex, const char* label); + void SetTabIcon(const BView* containedView, + const BBitmap* icon); void SetCloseButtonsAvailable(bool available); +private: + int32 _TabIndexForContainedView( + const BView* containedView) const; + private: #if INTEGRATE_MENU_INTO_TAB_BAR BMenu* fMenu;