From 65cc5e49ee22e22dae9204db37a33ab636f39bf3 Mon Sep 17 00:00:00 2001 From: stippi Date: Fri, 30 Apr 2010 15:08:05 +0000 Subject: [PATCH] The favicon is now also displayed in the URL input view. Mostly because one is used to it, but also when only one page is open and tabs are not displayed as per the user settings, the favicon would then not be visible. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@465 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserWindow.cpp | 12 +++- src/apps/webpositive/URLInputGroup.cpp | 94 ++++++++++++++++++++++++-- src/apps/webpositive/URLInputGroup.h | 4 ++ 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 9699ca2bd7..c5f9ce96e4 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -1174,8 +1174,14 @@ BrowserWindow::_TabChanged(int32 index) // Restore the previous focus or focus the web view. PageUserData* userData = static_cast( webView->GetUserData()); - if (userData != NULL && userData->FocusedView() != NULL) - userData->FocusedView()->MakeFocus(true); + BView* focusedView = NULL; + if (userData != NULL) { + focusedView = userData->FocusedView(); + fURLInputGroup->SetPageIcon(userData->PageIcon()); + } + + if (focusedView != NULL) + focusedView->MakeFocus(true); else webView->MakeFocus(true); @@ -1443,6 +1449,8 @@ BrowserWindow::_SetPageIcon(BWebView* view, const BBitmap* icon) // the TabManager for display in the respective tab. userData->SetPageIcon(icon); fTabManager->SetTabIcon(view, userData->PageIcon()); + if (view == CurrentWebView()) + fURLInputGroup->SetPageIcon(icon); } diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp index 6fb51e498c..4e252855b3 100644 --- a/src/apps/webpositive/URLInputGroup.cpp +++ b/src/apps/webpositive/URLInputGroup.cpp @@ -128,7 +128,7 @@ private: // #pragma mark - URLTextView -static const float kHorizontalTextRectInset = 3.0; +static const float kHorizontalTextRectInset = 4.0; class URLInputGroup::URLTextView : public BTextView { @@ -505,9 +505,14 @@ public: SetHighColor(0, 0, 0, 120); } - BPoint bitmapLocation(kFrameInset, kFrameInset); - if (Value() == B_CONTROL_ON) - bitmapLocation += BPoint(1, 1); + if (fBitmap == NULL) + return; + BRect bitmapBounds(fBitmap->Bounds()); + BPoint bitmapLocation( + floorf((bounds.left + bounds.right + - (bitmapBounds.left + bitmapBounds.right)) / 2 + 0.5f), + floorf((bounds.top + bounds.bottom + - (bitmapBounds.top + bitmapBounds.bottom)) / 2 + 0.5f)); DrawBitmap(fBitmap, bitmapLocation); } @@ -517,6 +522,76 @@ private: }; +// #pragma mark - IconView + + +class URLInputGroup::PageIconView : public BView { +public: + PageIconView() + : + BView("page icon view", B_WILL_DRAW), + fIcon(NULL) + { + SetDrawingMode(B_OP_OVER); + } + + ~PageIconView() + { + delete fIcon; + } + + virtual void Draw(BRect updateRect) + { + if (fIcon == NULL) + return; + + BRect bounds(Bounds()); + BRect iconBounds(fIcon->Bounds()); + BPoint iconPos( + floorf((bounds.left + bounds.right + - (iconBounds.left + iconBounds.right)) / 2 + 0.5f), + floorf((bounds.top + bounds.bottom + - (iconBounds.top + iconBounds.bottom)) / 2 + 0.5f)); + DrawBitmap(fIcon, iconPos); + } + + virtual BSize MinSize() + { + if (fIcon != NULL) { + return BSize(fIcon->Bounds().Width() + 3, + fIcon->Bounds().Height() + 3); + } + return BSize(0, 0); + } + + virtual BSize MaxSize() + { + return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); + } + + virtual BSize PreferredSize() + { + return MinSize(); + } + + void SetIcon(const BBitmap* icon) + { + if (icon == NULL && fIcon == NULL) + return; + delete fIcon; + if (icon) + fIcon = new BBitmap(icon); + else + fIcon = NULL; + Invalidate(); + InvalidateLayout(); + } + +private: + BBitmap* fIcon; +}; + + // #pragma mark - URLInputGroup @@ -527,6 +602,9 @@ URLInputGroup::URLInputGroup(BMessage* goMessage) { GroupLayout()->SetInsets(2, 2, 2, 2); + fIconView = new PageIconView(); + GroupLayout()->AddView(fIconView, 0.0f); + fTextView = new URLTextView(this); AddChild(fTextView); @@ -537,7 +615,7 @@ URLInputGroup::URLInputGroup(BMessage* goMessage) // fGoButton = new BitmapButton("kActionGo", NULL); fGoButton = new BitmapButton(kGoBitmapBits, kGoBitmapWidth, kGoBitmapHeight, kGoBitmapFormat, goMessage); - GroupLayout()->AddView(fGoButton, 0.0); + GroupLayout()->AddView(fGoButton, 0.0f); SetFlags(Flags() | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); SetLowColor(ViewColor()); @@ -622,3 +700,9 @@ URLInputGroup::GoButton() const } +void +URLInputGroup::SetPageIcon(const BBitmap* icon) +{ + fIconView->SetIcon(icon); +} + diff --git a/src/apps/webpositive/URLInputGroup.h b/src/apps/webpositive/URLInputGroup.h index 105b76d932..d71f713ca7 100644 --- a/src/apps/webpositive/URLInputGroup.h +++ b/src/apps/webpositive/URLInputGroup.h @@ -27,9 +27,13 @@ public: BButton* GoButton() const; + void SetPageIcon(const BBitmap* icon); + private: + class PageIconView; class URLTextView; + PageIconView* fIconView; URLTextView* fTextView; BButton* fGoButton; bool fWindowActive;