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
This commit is contained in:
stippi
2012-07-03 15:30:48 +02:00
committed by Alexandre Deckner
parent 10d5754b92
commit 6063974734
3 changed files with 91 additions and 12 deletions
+2 -1
View File
@@ -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);
}
+81 -10
View File
@@ -31,6 +31,7 @@
#include "WebView.h"
#include <Application.h>
#include <AbstractLayoutItem.h>
#include <Bitmap.h>
#include <Button.h>
#include <CardLayout.h>
#include <ControlLook.h>
@@ -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<TabLayoutItem*>(
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<WebTabView*>(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;
}
+8 -1
View File
@@ -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;