[haiku-webkit-commits] r259 - in webkit/trunk/WebKit/haiku: API WebCoreSupport WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Mon, 01 Mar 2010 18:46:15 +0000

Author: stippi
Date: Mon Mar  1 18:46:15 2010
New Revision: 259
URL: http://mmlr.dyndns.org/changeset/259

Log:
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.

Modified:
   webkit/trunk/WebKit/haiku/API/WebWindow.cpp
   webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp
   webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
   webkit/trunk/WebKit/haiku/WebPositive/WebTabView.cpp
   webkit/trunk/WebKit/haiku/WebPositive/WebTabView.h

Modified: webkit/trunk/WebKit/haiku/API/WebWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebWindow.cpp Mon Mar  1 17:46:43 2010        
(r258)
+++ webkit/trunk/WebKit/haiku/API/WebWindow.cpp Mon Mar  1 18:46:15 2010        
(r259)
@@ -90,8 +90,10 @@
         break;
     case NAVIGATION_REQUESTED: {
         BString url;
-        if (message->FindString("url", &url) == B_OK)
+        if (message->FindString("url", &url) == B_OK) {
             NavigationRequested(url, _WebViewForMessage(message));
+            _FetchIconForURL(url, *message);
+        }
         break;
     }
     case UPDATE_HISTORY: {

Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp Mon Mar 
 1 17:46:43 2010        (r258)
+++ webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp Mon Mar 
 1 18:46:15 2010        (r259)
@@ -507,6 +507,9 @@
 void 
FrameLoaderClientHaiku::dispatchDecidePolicyForNavigationAction(FramePolicyFunction
 function,
     const NavigationAction& action, const ResourceRequest& request, 
PassRefPtr<FormState> formState)
 {
+       BMessage message(NAVIGATION_REQUESTED);
+       message.AddString("url", request.url().string());
+       dispatchMessage(message);
     // Potentially we want to open a new window, when the user clicked with the
     // tertiary mouse button. That's why we can reuse the other method.
        dispatchDecidePolicyForNewWindowAction(function, action, request, 
formState, String());

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Mon Mar  1 
17:46:43 2010        (r258)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Mon Mar  1 
18:46:15 2010        (r259)
@@ -321,6 +321,7 @@
                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 @@
 void
 BrowserWindow::IconReceived(const BBitmap* icon, BWebView* view)
 {
-       printf("BrowserWindow::IconReceived(%p, %p)\n", icon, view);
+       fTabManager->SetTabIcon(view, icon);
 }
 
 

Modified: webkit/trunk/WebKit/haiku/WebPositive/WebTabView.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/WebTabView.cpp        Mon Mar  1 
17:46:43 2010        (r258)
+++ webkit/trunk/WebKit/haiku/WebPositive/WebTabView.cpp        Mon Mar  1 
18:46:15 2010        (r259)
@@ -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 @@
        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 @@
 }
 
 
+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 @@
 class WebTabView : public TabView {
 public:
        WebTabView(TabManagerController* controller);
+       ~WebTabView();
 
        virtual BSize MaxSize();
 
@@ -749,12 +763,15 @@
        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 @@
 WebTabView::WebTabView(TabManagerController* controller)
        :
        TabView(),
+       fIcon(NULL),
        fController(controller),
        fOverCloseRect(false),
        fClicked(false)
@@ -771,11 +789,21 @@
 }
 
 
+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 @@
        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 @@
 }
 
 
+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 @@
 
 
 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);
 }
 
 
@@ -1253,6 +1301,16 @@
 
 
 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)
 {
        if (available == fController->CloseButtonsAvailable())
@@ -1261,3 +1319,16 @@
        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;
+}
+

Modified: webkit/trunk/WebKit/haiku/WebPositive/WebTabView.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/WebTabView.h  Mon Mar  1 17:46:43 
2010        (r258)
+++ webkit/trunk/WebKit/haiku/WebPositive/WebTabView.h  Mon Mar  1 18:46:15 
2010        (r259)
@@ -36,6 +36,7 @@
     CLOSE_TAB = 'cltb'
 };
 
+class BBitmap;
 class BCardLayout;
 class BGroupView;
 class BMenu;
@@ -61,7 +62,7 @@
                        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,9 +72,15 @@
                        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;
 #endif

Other related posts: