From dcad381777abe240b6c4ce4a2da9f1dd445e4b0c Mon Sep 17 00:00:00 2001 From: stippi Date: Sat, 13 Mar 2010 14:10:14 +0000 Subject: [PATCH] Bugfixes for tab view click events: * When adding/removing tabs, process a fake mouse moved event to synchronize with the new tab layout. * Count the mouse clicks for the "double click into empty area opens new tab" feature in such a way that clicks into tabs never count (closing a tab was the first click before, the second would immediately open a new tab and similar issues). git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@309 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/WebTabView.cpp | 78 +++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/src/apps/webpositive/WebTabView.cpp b/src/apps/webpositive/WebTabView.cpp index 4dbb0bfc70..9f40c9aeef 100644 --- a/src/apps/webpositive/WebTabView.cpp +++ b/src/apps/webpositive/WebTabView.cpp @@ -111,7 +111,7 @@ private: private: TabContainerView* fContainerView; TabLayoutItem* fLayoutItem; - + BString fLabel; bool fIsFirst; @@ -145,6 +145,8 @@ public: virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); + virtual void DoLayout(); + void AddTab(const char* label, int32 index = -1); void AddTab(TabView* tab, int32 index = -1); TabView* RemoveTab(int32 index); @@ -159,10 +161,13 @@ public: private: TabView* _TabAt(const BPoint& where) const; + void _MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); private: TabView* fLastMouseEventTab; bool fMouseDown; + uint32 fClickCount; TabView* fSelectedTab; Controller* fController; }; @@ -179,6 +184,7 @@ TabContainerView::TabContainerView(Controller* controller) BGroupView(B_HORIZONTAL), fLastMouseEventTab(NULL), fMouseDown(false), + fClickCount(0), fSelectedTab(NULL), fController(controller) { @@ -260,8 +266,12 @@ TabContainerView::MouseDown(BPoint where) SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); if (fLastMouseEventTab) fLastMouseEventTab->MouseDown(where, buttons); - else if (clicks > 1) - fController->DoubleClickOutsideTabs(); + else { + if (clicks > 1) + fClickCount++; + else + fClickCount = 1; + } } @@ -271,6 +281,10 @@ TabContainerView::MouseUp(BPoint where) fMouseDown = false; if (fLastMouseEventTab) fLastMouseEventTab->MouseUp(where); + else if (fClickCount > 1) { + fClickCount = 0; + fController->DoubleClickOutsideTabs(); + } } @@ -278,27 +292,22 @@ void TabContainerView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) { - TabView* tab = _TabAt(where); - if (fMouseDown) { - uint32 transit = tab == fLastMouseEventTab - ? B_INSIDE_VIEW : B_OUTSIDE_VIEW; - if (fLastMouseEventTab) - fLastMouseEventTab->MouseMoved(where, transit, dragMessage); - return; - } - - if (fLastMouseEventTab && fLastMouseEventTab == tab) - fLastMouseEventTab->MouseMoved(where, B_INSIDE_VIEW, dragMessage); - else { - if (fLastMouseEventTab) - fLastMouseEventTab->MouseMoved(where, B_EXITED_VIEW, dragMessage); - fLastMouseEventTab = tab; - if (fLastMouseEventTab) - fLastMouseEventTab->MouseMoved(where, B_ENTERED_VIEW, dragMessage); - } + _MouseMoved(where, transit, dragMessage); } +void +TabContainerView::DoLayout() +{ + BGroupView::DoLayout(); + + BPoint where; + uint32 buttons; + GetMouse(&where, &buttons, false); + if (Bounds().Contains(where)) + _MouseMoved(where, B_INSIDE_VIEW, NULL); +} + void TabContainerView::AddTab(const char* label, int32 index) { @@ -416,7 +425,7 @@ TabContainerView::SelectTab(int32 index) GroupLayout()->ItemAt(index)); if (item) tab = item->Parent(); - + SelectTab(tab); } @@ -472,6 +481,31 @@ TabContainerView::_TabAt(const BPoint& where) const } +void +TabContainerView::_MouseMoved(BPoint where, uint32 _transit, + const BMessage* dragMessage) +{ + TabView* tab = _TabAt(where); + if (fMouseDown) { + uint32 transit = tab == fLastMouseEventTab + ? B_INSIDE_VIEW : B_OUTSIDE_VIEW; + if (fLastMouseEventTab) + fLastMouseEventTab->MouseMoved(where, transit, dragMessage); + return; + } + + if (fLastMouseEventTab && fLastMouseEventTab == tab) + fLastMouseEventTab->MouseMoved(where, B_INSIDE_VIEW, dragMessage); + else { + if (fLastMouseEventTab) + fLastMouseEventTab->MouseMoved(where, B_EXITED_VIEW, dragMessage); + fLastMouseEventTab = tab; + if (fLastMouseEventTab) + fLastMouseEventTab->MouseMoved(where, B_ENTERED_VIEW, dragMessage); + } +} + + // #pragma mark - TabView