Commit 28c3d0a9 authored by jianli@chromium.org's avatar jianli@chromium.org

Switch to doing user-resizing via system for panels on Mac

We used to track and handle user-resizing by ourselves. This brings up a few problems and makes the user-resizing hard to use on Mac. For example, the user-resizing could not be triggered outside or on the edge. Switching to doing it via system solve all these problems.

Also removed EnableResizeByMouse which is not really used in our code.

BUG=282652,282657
TEST=manual test by user-resizing panels

Review URL: https://chromiumcodereview.appspot.com/23918002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221651 0039d316-1c4b-4281-b951-d872f2087c98
parent 0130137b
...@@ -46,7 +46,6 @@ class PanelCocoa : public NativePanel { ...@@ -46,7 +46,6 @@ class PanelCocoa : public NativePanel {
virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE; virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE;
virtual bool IsPanelAlwaysOnTop() const OVERRIDE; virtual bool IsPanelAlwaysOnTop() const OVERRIDE;
virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE; virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE;
virtual void EnableResizeByMouse(bool enable) OVERRIDE;
virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE;
virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE; virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE;
virtual void PanelExpansionStateChanging( virtual void PanelExpansionStateChanging(
......
...@@ -261,10 +261,6 @@ void PanelCocoa::SetPanelAlwaysOnTop(bool on_top) { ...@@ -261,10 +261,6 @@ void PanelCocoa::SetPanelAlwaysOnTop(bool on_top) {
[controller_ updateWindowCollectionBehavior]; [controller_ updateWindowCollectionBehavior];
} }
void PanelCocoa::EnableResizeByMouse(bool enable) {
[controller_ enableResizeByMouse:enable];
}
void PanelCocoa::UpdatePanelMinimizeRestoreButtonVisibility() { void PanelCocoa::UpdatePanelMinimizeRestoreButtonVisibility() {
[controller_ updateTitleBarMinimizeRestoreButtonVisibility]; [controller_ updateTitleBarMinimizeRestoreButtonVisibility];
} }
......
...@@ -12,18 +12,23 @@ ...@@ -12,18 +12,23 @@
namespace cocoa_utils { namespace cocoa_utils {
// TODO(dcheng): Move elsewhere so BrowserWindowCocoa can use them too. // TODO(dcheng): Move elsewhere so BrowserWindowCocoa can use them too.
// Converts a rect from the platfrom-independent screen coordinates (with the // Converts a rect from the platform-independent screen coordinates (with the
// (0,0) in the top-left corner of the primary screen) to the Cocoa screen // (0,0) in the top-left corner of the primary screen) to the Cocoa screen
// coordinates (with (0,0) in the low-left corner). // coordinates (with (0,0) in the low-left corner).
NSRect ConvertRectToCocoaCoordinates(const gfx::Rect& bounds); NSRect ConvertRectToCocoaCoordinates(const gfx::Rect& bounds);
// Converts a point from the platfrom-independent screen coordinates (with the // Converts a rect from the Cocoa screen oordinates (with (0,0) in the low-left
// corner) to the platform-independent screen coordinates (with the (0,0) in
// the top-left corner of the primary screen).
gfx::Rect ConvertRectFromCocoaCoordinates(NSRect bounds);
// Converts a point from the platform-independent screen coordinates (with the
// (0,0) in the top-left corner of the primary screen) to the Cocoa screen // (0,0) in the top-left corner of the primary screen) to the Cocoa screen
// coordinates (with (0,0) in the low-left corner). // coordinates (with (0,0) in the low-left corner).
NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point); NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point);
// Converts a point from the Cocoa screen coordinates (with (0,0) in the // Converts a point from the Cocoa screen coordinates (with (0,0) in the
// low-left corner of the primary screen) to the platfrom-independent screen // low-left corner of the primary screen) to the platform-independent screen
// coordinates (with the (0,0) in the top-left corner). // coordinates (with the (0,0) in the top-left corner).
gfx::Point ConvertPointFromCocoaCoordinates(NSPoint point); gfx::Point ConvertPointFromCocoaCoordinates(NSPoint point);
......
...@@ -15,6 +15,15 @@ NSRect ConvertRectToCocoaCoordinates(const gfx::Rect& bounds) { ...@@ -15,6 +15,15 @@ NSRect ConvertRectToCocoaCoordinates(const gfx::Rect& bounds) {
bounds.width(), bounds.height()); bounds.width(), bounds.height());
} }
gfx::Rect ConvertRectFromCocoaCoordinates(NSRect bounds) {
// Flip coordinates based on the primary screen.
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
return gfx::Rect(
NSMinX(bounds), NSHeight([screen frame]) - NSMaxY(bounds),
NSWidth(bounds), NSHeight(bounds));
}
NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point) { NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point) {
// Flip coordinates based on the primary screen. // Flip coordinates based on the primary screen.
NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#import "chrome/browser/ui/cocoa/chrome_browser_window.h" #import "chrome/browser/ui/cocoa/chrome_browser_window.h"
#include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel.h"
#import "ui/base/cocoa/tracking_area.h"
class PanelCocoa; class PanelCocoa;
@class PanelTitlebarViewCocoa; @class PanelTitlebarViewCocoa;
...@@ -42,12 +43,17 @@ class PanelCocoa; ...@@ -42,12 +43,17 @@ class PanelCocoa;
// window over other application windows due to panels having a higher // window over other application windows due to panels having a higher
// priority NSWindowLevel, so we distinguish between the two scenarios. // priority NSWindowLevel, so we distinguish between the two scenarios.
BOOL activationRequestedByPanel_; BOOL activationRequestedByPanel_;
base::scoped_nsobject<NSView> overlayView_; // Is user resizing in progress?
BOOL userResizing_;
// Tracks the whole window in order to receive NSMouseMoved event.
ui::ScopedCrTrackingArea trackingArea_;
} }
// Load the window nib and do any Cocoa-specific initialization. // Load the window nib and do any Cocoa-specific initialization.
- (id)initWithPanel:(PanelCocoa*)window; - (id)initWithPanel:(PanelCocoa*)window;
- (Panel*)panel;
- (void)webContentsInserted:(content::WebContents*)contents; - (void)webContentsInserted:(content::WebContents*)contents;
- (void)webContentsDetached:(content::WebContents*)contents; - (void)webContentsDetached:(content::WebContents*)contents;
...@@ -137,8 +143,9 @@ class PanelCocoa; ...@@ -137,8 +143,9 @@ class PanelCocoa;
// Adjusts NSWindowCollectionBehavior based on whether panel is always on top. // Adjusts NSWindowCollectionBehavior based on whether panel is always on top.
- (void)updateWindowCollectionBehavior; - (void)updateWindowCollectionBehavior;
// Turns on user-resizable corners/sides indications and enables live resize. // Updates the tracking area per the window size change. This is needed in
- (void)enableResizeByMouse:(BOOL)enable; // order to receive the NSMouseMoved notification.
- (void)updateTrackingArea;
// Turns on/off shadow effect around the window shape. // Turns on/off shadow effect around the window shape.
- (void)showShadow:(BOOL)show; - (void)showShadow:(BOOL)show;
...@@ -148,6 +155,10 @@ class PanelCocoa; ...@@ -148,6 +155,10 @@ class PanelCocoa;
// Returns true if the window is minimized to the dock. // Returns true if the window is minimized to the dock.
- (BOOL)isMiniaturized; - (BOOL)isMiniaturized;
// Returns true if the user-resizing is allowed for the edge/corner close to
// current mouse location.
- (BOOL)canResizeByMouseAtCurrentLocation;
- (NSRect)frameRectForContentRect:(NSRect)contentRect; - (NSRect)frameRectForContentRect:(NSRect)contentRect;
- (NSRect)contentRectForFrameRect:(NSRect)frameRect; - (NSRect)contentRectForFrameRect:(NSRect)frameRect;
......
...@@ -1068,9 +1068,6 @@ void PanelGtk::SetPanelAlwaysOnTop(bool on_top) { ...@@ -1068,9 +1068,6 @@ void PanelGtk::SetPanelAlwaysOnTop(bool on_top) {
gtk_window_unstick(window_); gtk_window_unstick(window_);
} }
void PanelGtk::EnableResizeByMouse(bool enable) {
}
void PanelGtk::UpdatePanelMinimizeRestoreButtonVisibility() { void PanelGtk::UpdatePanelMinimizeRestoreButtonVisibility() {
titlebar_->UpdateMinimizeRestoreButtonVisibility(); titlebar_->UpdateMinimizeRestoreButtonVisibility();
} }
......
...@@ -78,7 +78,6 @@ class PanelGtk : public NativePanel, ...@@ -78,7 +78,6 @@ class PanelGtk : public NativePanel,
virtual int TitleOnlyHeight() const OVERRIDE; virtual int TitleOnlyHeight() const OVERRIDE;
virtual bool IsPanelAlwaysOnTop() const OVERRIDE; virtual bool IsPanelAlwaysOnTop() const OVERRIDE;
virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE; virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE;
virtual void EnableResizeByMouse(bool enable) OVERRIDE;
virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE;
virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE; virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE;
virtual void MinimizePanelBySystem() OVERRIDE; virtual void MinimizePanelBySystem() OVERRIDE;
......
...@@ -239,7 +239,6 @@ void DetachedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { ...@@ -239,7 +239,6 @@ void DetachedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) {
static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
Panel::USE_SYSTEM_ATTENTION)); Panel::USE_SYSTEM_ATTENTION));
panel->ShowShadow(true); panel->ShowShadow(true);
panel->EnableResizeByMouse(true);
panel->UpdateMinimizeRestoreButtonVisibility(); panel->UpdateMinimizeRestoreButtonVisibility();
panel->SetWindowCornerStyle(panel::ALL_ROUNDED); panel->SetWindowCornerStyle(panel::ALL_ROUNDED);
} }
......
...@@ -765,7 +765,6 @@ void DockedPanelCollection::CloseAll() { ...@@ -765,7 +765,6 @@ void DockedPanelCollection::CloseAll() {
void DockedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { void DockedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) {
panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); panel->set_attention_mode(Panel::USE_PANEL_ATTENTION);
panel->ShowShadow(true); panel->ShowShadow(true);
panel->EnableResizeByMouse(true);
panel->UpdateMinimizeRestoreButtonVisibility(); panel->UpdateMinimizeRestoreButtonVisibility();
panel->SetWindowCornerStyle(panel::TOP_ROUNDED); panel->SetWindowCornerStyle(panel::TOP_ROUNDED);
} }
......
...@@ -72,9 +72,6 @@ class NativePanel { ...@@ -72,9 +72,6 @@ class NativePanel {
virtual bool IsPanelAlwaysOnTop() const = 0; virtual bool IsPanelAlwaysOnTop() const = 0;
virtual void SetPanelAlwaysOnTop(bool on_top) = 0; virtual void SetPanelAlwaysOnTop(bool on_top) = 0;
// Enables resizing by dragging edges/corners.
virtual void EnableResizeByMouse(bool enable) = 0;
// Updates the visibility of the minimize and restore buttons. // Updates the visibility of the minimize and restore buttons.
virtual void UpdatePanelMinimizeRestoreButtonVisibility() = 0; virtual void UpdatePanelMinimizeRestoreButtonVisibility() = 0;
......
...@@ -667,11 +667,6 @@ void Panel::SetPreviewMode(bool in_preview) { ...@@ -667,11 +667,6 @@ void Panel::SetPreviewMode(bool in_preview) {
in_preview_mode_ = in_preview; in_preview_mode_ = in_preview;
} }
void Panel::EnableResizeByMouse(bool enable) {
DCHECK(native_panel_);
native_panel_->EnableResizeByMouse(enable);
}
void Panel::UpdateMinimizeRestoreButtonVisibility() { void Panel::UpdateMinimizeRestoreButtonVisibility() {
native_panel_->UpdatePanelMinimizeRestoreButtonVisibility(); native_panel_->UpdatePanelMinimizeRestoreButtonVisibility();
} }
......
...@@ -252,10 +252,6 @@ class Panel : public ui::BaseWindow, ...@@ -252,10 +252,6 @@ class Panel : public ui::BaseWindow,
// being dragged, it is in preview mode. // being dragged, it is in preview mode.
void SetPreviewMode(bool in_preview_mode); void SetPreviewMode(bool in_preview_mode);
// Sets up the panel for being resizable by the user - for example,
// enables the resize mouse cursors when mouse is hovering over the edges.
void EnableResizeByMouse(bool enable);
// Sets whether the minimize or restore button, if any, are visible. // Sets whether the minimize or restore button, if any, are visible.
void UpdateMinimizeRestoreButtonVisibility(); void UpdateMinimizeRestoreButtonVisibility();
......
...@@ -626,7 +626,6 @@ void StackedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { ...@@ -626,7 +626,6 @@ void StackedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) {
static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
Panel::USE_SYSTEM_ATTENTION)); Panel::USE_SYSTEM_ATTENTION));
panel->ShowShadow(false); panel->ShowShadow(false);
panel->EnableResizeByMouse(true);
panel->UpdateMinimizeRestoreButtonVisibility(); panel->UpdateMinimizeRestoreButtonVisibility();
UpdatePanelCornerStyle(panel); UpdatePanelCornerStyle(panel);
} }
......
...@@ -599,10 +599,6 @@ void PanelView::SetPanelAlwaysOnTop(bool on_top) { ...@@ -599,10 +599,6 @@ void PanelView::SetPanelAlwaysOnTop(bool on_top) {
window_->client_view()->Layout(); window_->client_view()->Layout();
} }
void PanelView::EnableResizeByMouse(bool enable) {
// Nothing to do since we use system resizing.
}
void PanelView::UpdatePanelMinimizeRestoreButtonVisibility() { void PanelView::UpdatePanelMinimizeRestoreButtonVisibility() {
GetFrameView()->UpdateTitlebarMinimizeRestoreButtonVisibility(); GetFrameView()->UpdateTitlebarMinimizeRestoreButtonVisibility();
} }
......
...@@ -63,7 +63,6 @@ class PanelView : public NativePanel, ...@@ -63,7 +63,6 @@ class PanelView : public NativePanel,
virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE; virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE;
virtual bool IsPanelAlwaysOnTop() const OVERRIDE; virtual bool IsPanelAlwaysOnTop() const OVERRIDE;
virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE; virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE;
virtual void EnableResizeByMouse(bool enable) OVERRIDE;
virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE;
virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE; virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE;
virtual void PanelExpansionStateChanging( virtual void PanelExpansionStateChanging(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment