summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authordimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-21 22:10:44 +0000
committerdimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-21 22:10:44 +0000
commit0d52e41eda4a170aed7a7a5c46c93af942c50dbb (patch)
tree2a6585b9b3cdfcc2f0490b37b50af01634f468f1 /chrome/browser/ui
parent00ddc6493e5f6d2940807fa23b6e267aecfb10c9 (diff)
downloadchromium_src-0d52e41eda4a170aed7a7a5c46c93af942c50dbb.zip
chromium_src-0d52e41eda4a170aed7a7a5c46c93af942c50dbb.tar.gz
chromium_src-0d52e41eda4a170aed7a7a5c46c93af942c50dbb.tar.bz2
Rename PanelMouseWatcherGtk into PanelMouseWatcherTimer. Added implementation of gfx::Point GetCursorScreenPoint() on Mac.
Review URL: http://codereview.chromium.org/7981012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102173 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/panels/native_panel.h1
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_cocoa.mm22
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc14
-rw-r--r--chrome/browser/ui/panels/panel_mouse_watcher.cc1
-rw-r--r--chrome/browser/ui/panels/panel_mouse_watcher_timer.cc (renamed from chrome/browser/ui/panels/panel_mouse_watcher_gtk.cc)45
-rw-r--r--chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm10
6 files changed, 56 insertions, 37 deletions
diff --git a/chrome/browser/ui/panels/native_panel.h b/chrome/browser/ui/panels/native_panel.h
index d25ae21..08d82e4 100644
--- a/chrome/browser/ui/panels/native_panel.h
+++ b/chrome/browser/ui/panels/native_panel.h
@@ -87,6 +87,7 @@ class NativePanel {
class NativePanelTesting {
public:
static NativePanelTesting* Create(NativePanel* native_panel);
+ // TODO(dimich) Remove this method, there is PanelMouseWatcher::GetInstance().
static PanelMouseWatcher* GetPanelMouseWatcherInstance();
// clang gives error on delete if the destructor is not virtual.
diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
index a2a90cc..5afc84e 100644
--- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
@@ -10,6 +10,7 @@
#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
+#include "chrome/browser/ui/panels/panel_mouse_watcher.h"
#import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h"
#import "chrome/browser/ui/panels/panel_window_controller_cocoa.h"
#include "content/common/native_web_keyboard_event.h"
@@ -58,6 +59,9 @@ PanelBrowserWindowCocoa::PanelBrowserWindowCocoa(Browser* browser,
}
PanelBrowserWindowCocoa::~PanelBrowserWindowCocoa() {
+ PanelMouseWatcher* watcher = PanelMouseWatcher::GetInstance();
+ if (watcher->IsSubscribed(this))
+ watcher->RemoveSubscriber(this);
}
bool PanelBrowserWindowCocoa::isClosed() {
@@ -109,13 +113,15 @@ void PanelBrowserWindowCocoa::OnPanelExpansionStateChanged(
int height; // New height of the Panel in screen coordinates.
switch (expansion_state) {
case Panel::EXPANDED:
+ PanelMouseWatcher::GetInstance()->RemoveSubscriber(this);
height = restored_height_;
break;
case Panel::TITLE_ONLY:
height = [controller_ titlebarHeightInScreenCoordinates];
break;
case Panel::MINIMIZED:
- height = 3; // TODO(dimich) merge with GTK patch which defines it better.
+ PanelMouseWatcher::GetInstance()->AddSubscriber(this);
+ height = PanelManager::minimized_panel_height();
break;
default:
NOTREACHED();
@@ -133,10 +139,11 @@ void PanelBrowserWindowCocoa::OnPanelExpansionStateChanged(
SetPanelBounds(bounds);
}
+// Coordinates are in gfx coordinate system (screen, with 0,0 at the top left).
bool PanelBrowserWindowCocoa::ShouldBringUpPanelTitlebar(int mouse_x,
int mouse_y) const {
- NOTIMPLEMENTED();
- return false;
+ return bounds_.x() <= mouse_x && mouse_x <= bounds_.right() &&
+ mouse_y >= bounds_.y();
}
void PanelBrowserWindowCocoa::ClosePanel() {
@@ -300,7 +307,7 @@ NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) {
// static
PanelMouseWatcher* NativePanelTesting::GetPanelMouseWatcherInstance() {
- return NULL;
+ return PanelMouseWatcher::GetInstance();
}
NativePanelTestingCocoa::NativePanelTestingCocoa(NativePanel* native_panel)
@@ -332,12 +339,13 @@ void NativePanelTestingCocoa::FinishDragTitlebar() {
[titlebar() finishDragTitlebar];
}
+// TODO(dimich) this method is platform-independent. Reuse it.
void NativePanelTestingCocoa::SetMousePositionForMinimizeRestore(
const gfx::Point& hover_point) {
- NOTIMPLEMENTED();
+ PanelMouseWatcher::GetInstance()->HandleMouseMovement(hover_point);
+ MessageLoopForUI::current()->RunAllPending();
}
int NativePanelTestingCocoa::TitleOnlyHeight() const {
- NOTIMPLEMENTED();
- return -1;
+ return [native_panel_window_->controller_ titlebarHeightInScreeenCoordinates];
}
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index aa80b2e..cd37946 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -306,6 +306,12 @@ class PanelBrowserTest : public BasePanelBrowserTest {
}
void TestMinimizeRestore() {
+ // This constant is used to generate a point 'sufficiently higher then
+ // top edge of the panel'. On some platforms (Mac) we extend hover area
+ // a bit above the minimized panel as well, so it takes significant
+ // distance to 'move mouse out' of the hover-sensitive area.
+ const int kFarEnoughFromHoverArea = 153;
+
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<gfx::Rect> test_begin_bounds = GetAllPanelsBounds();
std::vector<gfx::Rect> expected_bounds = test_begin_bounds;
@@ -367,7 +373,8 @@ class PanelBrowserTest : public BasePanelBrowserTest {
CheckExpansionStates(titlebar_exposed_states);
// Hover mouse above the panel. Verify all panels are minimized.
- hover_point.set_y(panels[index]->GetRestoredBounds().y() - 10);
+ hover_point.set_y(
+ panels[index]->GetRestoredBounds().y() - kFarEnoughFromHoverArea);
native_panels_testing[index]->SetMousePositionForMinimizeRestore(
hover_point);
CheckPanelBounds(panels, minimized_bounds);
@@ -391,7 +398,8 @@ class PanelBrowserTest : public BasePanelBrowserTest {
CheckExpansionStates(titlebar_exposed_states);
// Hover mouse above panel. Verify all panels are minimized.
- hover_point.set_y(panels[index]->GetRestoredBounds().y() - 10);
+ hover_point.set_y(
+ panels[index]->GetRestoredBounds().y() - kFarEnoughFromHoverArea);
native_panels_testing[index]->SetMousePositionForMinimizeRestore(
hover_point);
CheckPanelBounds(panels, minimized_bounds);
@@ -816,7 +824,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AutoResize) {
panel->Close();
}
-#if defined(TOOLKIT_GTK)
+#if defined(TOOLKIT_GTK) || defined(OS_MACOSX)
#define MAYBE_MinimizeRestore MinimizeRestore
#else
#define MAYBE_MinimizeRestore DISABLED_MinimizeRestore
diff --git a/chrome/browser/ui/panels/panel_mouse_watcher.cc b/chrome/browser/ui/panels/panel_mouse_watcher.cc
index bf1f437..77e5f5b 100644
--- a/chrome/browser/ui/panels/panel_mouse_watcher.cc
+++ b/chrome/browser/ui/panels/panel_mouse_watcher.cc
@@ -11,6 +11,7 @@ PanelMouseWatcher::PanelMouseWatcher()
}
PanelMouseWatcher::~PanelMouseWatcher() {
+ DCHECK(subscribers_.size() == 0);
}
void PanelMouseWatcher::AddSubscriber(NativePanel* native_panel) {
diff --git a/chrome/browser/ui/panels/panel_mouse_watcher_gtk.cc b/chrome/browser/ui/panels/panel_mouse_watcher_timer.cc
index 9ae6002..089d3e9 100644
--- a/chrome/browser/ui/panels/panel_mouse_watcher_gtk.cc
+++ b/chrome/browser/ui/panels/panel_mouse_watcher_timer.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// #include "chrome/browser/ui/panels/panel_mouse_watcher_gtk.h"
-
#include "base/memory/singleton.h"
#include "base/time.h"
#include "base/timer.h"
@@ -11,14 +9,14 @@
#include "chrome/browser/ui/panels/panel_mouse_watcher.h"
#include "ui/gfx/screen.h"
-// A timer based implementation of PanelMouseWatcher. Currently used on Gtk
-// but could be used on any platform.
-class PanelMouseWatcherGtk : public PanelMouseWatcher {
+// A timer based implementation of PanelMouseWatcher. Currently used for Gtk
+// and Mac panels implementations.
+class PanelMouseWatcherTimer : public PanelMouseWatcher {
public:
// Returns the singleton instance.
- static PanelMouseWatcherGtk* GetInstance();
+ static PanelMouseWatcherTimer* GetInstance();
- virtual ~PanelMouseWatcherGtk();
+ virtual ~PanelMouseWatcherTimer();
protected:
virtual void Start();
@@ -28,50 +26,51 @@ class PanelMouseWatcherGtk : public PanelMouseWatcher {
// Specifies the rate at which we want to sample the mouse position.
static const int kMousePollingIntervalMs = 250;
- PanelMouseWatcherGtk();
- friend struct DefaultSingletonTraits<PanelMouseWatcherGtk>;
+ PanelMouseWatcherTimer();
+ friend struct DefaultSingletonTraits<PanelMouseWatcherTimer>;
// Timer callback function.
void DoWork();
- friend class base::RepeatingTimer<PanelMouseWatcherGtk>;
+ friend class base::RepeatingTimer<PanelMouseWatcherTimer>;
- // Timer used to track mouse movements. Gtk does not provide an easy way of
- // tracking mouse movements across applications. So we use a timer to
+ // Timer used to track mouse movements. Some OSes do not provide an easy way
+ // of tracking mouse movements across applications. So we use a timer to
// accomplish the same. This could also be more efficient as you end up
// getting a lot of notifications when tracking mouse movements.
- base::RepeatingTimer<PanelMouseWatcherGtk> timer_;
+ base::RepeatingTimer<PanelMouseWatcherTimer> timer_;
- DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherGtk);
+ DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherTimer);
};
// static
PanelMouseWatcher* PanelMouseWatcher::GetInstance() {
- return PanelMouseWatcherGtk::GetInstance();
+ return PanelMouseWatcherTimer::GetInstance();
}
// static
-PanelMouseWatcherGtk* PanelMouseWatcherGtk::GetInstance() {
- return Singleton<PanelMouseWatcherGtk>::get();
+PanelMouseWatcherTimer* PanelMouseWatcherTimer::GetInstance() {
+ return Singleton<PanelMouseWatcherTimer>::get();
}
-PanelMouseWatcherGtk::PanelMouseWatcherGtk() : PanelMouseWatcher() {
+PanelMouseWatcherTimer::PanelMouseWatcherTimer() : PanelMouseWatcher() {
}
-PanelMouseWatcherGtk::~PanelMouseWatcherGtk() {
+PanelMouseWatcherTimer::~PanelMouseWatcherTimer() {
+ DCHECK(!timer_.IsRunning());
}
-void PanelMouseWatcherGtk::Start() {
+void PanelMouseWatcherTimer::Start() {
DCHECK(!timer_.IsRunning());
timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kMousePollingIntervalMs),
- this, &PanelMouseWatcherGtk::DoWork);
+ this, &PanelMouseWatcherTimer::DoWork);
}
-void PanelMouseWatcherGtk::Stop() {
+void PanelMouseWatcherTimer::Stop() {
DCHECK(timer_.IsRunning());
timer_.Stop();
}
-void PanelMouseWatcherGtk::DoWork() {
+void PanelMouseWatcherTimer::DoWork() {
HandleMouseMovement(gfx::Screen::GetCursorScreenPoint());
}
diff --git a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
index 08fdc1b..7483b5e 100644
--- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
@@ -24,7 +24,9 @@ const int kRoundedCornerSize = 3;
const int kCloseButtonLeftPadding = 8;
// Used to implement TestingAPI
-static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) {
+static NSEvent* MakeMouseEvent(NSEventType type,
+ NSPoint point,
+ int clickCount) {
return [NSEvent mouseEventWithType:type
location:point
modifierFlags:0
@@ -32,7 +34,7 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) {
windowNumber:0
context:nil
eventNumber:0
- clickCount:0
+ clickCount:clickCount
pressure:0.0];
}
@@ -347,12 +349,12 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) {
}
- (void)pressLeftMouseButtonTitlebar {
- NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint);
+ NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint, 0);
[self mouseDown:event];
}
- (void)releaseLeftMouseButtonTitlebar {
- NSEvent* event = MakeMouseEvent(NSLeftMouseUp, NSZeroPoint);
+ NSEvent* event = MakeMouseEvent(NSLeftMouseUp, NSZeroPoint, 1);
[self mouseUp:event];
}