Commit d27987c3 authored by ben@chromium.org's avatar ben@chromium.org

Move last of event handlers down to NativeWidgetWin/Gtk.

BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/7129022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88564 0039d316-1c4b-4281-b951-d872f2087c98
parent 4f16c20c
...@@ -31,9 +31,9 @@ class BrowserFrameGtk : public views::NativeWindowGtk, ...@@ -31,9 +31,9 @@ class BrowserFrameGtk : public views::NativeWindowGtk,
// Overridden from views::NativeWindowGtk: // Overridden from views::NativeWindowGtk:
virtual gboolean OnWindowStateEvent(GtkWidget* widget, virtual gboolean OnWindowStateEvent(GtkWidget* widget,
GdkEventWindowState* event); GdkEventWindowState* event) OVERRIDE;
virtual gboolean OnConfigureEvent(GtkWidget* widget, virtual gboolean OnConfigureEvent(GtkWidget* widget,
GdkEventConfigure* event); GdkEventConfigure* event) OVERRIDE;
private: private:
NativeBrowserFrameDelegate* delegate_; NativeBrowserFrameDelegate* delegate_;
......
...@@ -162,6 +162,9 @@ class NativeWidget { ...@@ -162,6 +162,9 @@ class NativeWidget {
// accelerated drawing. // accelerated drawing.
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
// Makes the NativeWindow modal.
virtual void BecomeModal() = 0;
// Widget pass-thrus, private to Views. -------------------------------------- // Widget pass-thrus, private to Views. --------------------------------------
// See method documentation in Widget. // See method documentation in Widget.
virtual gfx::Rect GetWindowScreenBounds() const = 0; virtual gfx::Rect GetWindowScreenBounds() const = 0;
......
...@@ -24,6 +24,12 @@ class NativeWidgetDelegate { ...@@ -24,6 +24,12 @@ class NativeWidgetDelegate {
public: public:
virtual ~NativeWidgetDelegate() {} virtual ~NativeWidgetDelegate() {}
// Returns true if the window is modal.
virtual bool IsModal() const = 0;
// Returns true if the window is a dialog box.
virtual bool IsDialogBox() const = 0;
// Returns true if the window can be activated. // Returns true if the window can be activated.
virtual bool CanActivate() const = 0; virtual bool CanActivate() const = 0;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ui/base/gtk/scoped_handle_gtk.h" #include "ui/base/gtk/scoped_handle_gtk.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/gfx/canvas_skia_paint.h" #include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "views/controls/textfield/native_textfield_views.h" #include "views/controls/textfield/native_textfield_views.h"
#include "views/focus/view_storage.h" #include "views/focus/view_storage.h"
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
#include "views/widget/gtk_views_window.h" #include "views/widget/gtk_views_window.h"
#include "views/widget/tooltip_manager_gtk.h" #include "views/widget/tooltip_manager_gtk.h"
#include "views/widget/widget_delegate.h" #include "views/widget/widget_delegate.h"
#include "views/window/hit_test.h"
#include "views/window/native_window_gtk.h" #include "views/window/native_window_gtk.h"
#if defined(TOUCH_UI) #if defined(TOUCH_UI)
...@@ -192,6 +194,61 @@ GtkWindowType WindowTypeToGtkWindowType(Widget::InitParams::Type type) { ...@@ -192,6 +194,61 @@ GtkWindowType WindowTypeToGtkWindowType(Widget::InitParams::Type type) {
return GTK_WINDOW_TOPLEVEL; return GTK_WINDOW_TOPLEVEL;
} }
// Converts a Windows-style hit test result code into a GDK window edge.
GdkWindowEdge HitTestCodeToGDKWindowEdge(int hittest_code) {
switch (hittest_code) {
case HTBOTTOM:
return GDK_WINDOW_EDGE_SOUTH;
case HTBOTTOMLEFT:
return GDK_WINDOW_EDGE_SOUTH_WEST;
case HTBOTTOMRIGHT:
case HTGROWBOX:
return GDK_WINDOW_EDGE_SOUTH_EAST;
case HTLEFT:
return GDK_WINDOW_EDGE_WEST;
case HTRIGHT:
return GDK_WINDOW_EDGE_EAST;
case HTTOP:
return GDK_WINDOW_EDGE_NORTH;
case HTTOPLEFT:
return GDK_WINDOW_EDGE_NORTH_WEST;
case HTTOPRIGHT:
return GDK_WINDOW_EDGE_NORTH_EAST;
default:
NOTREACHED();
break;
}
// Default to something defaultish.
return HitTestCodeToGDKWindowEdge(HTGROWBOX);
}
// Converts a Windows-style hit test result code into a GDK cursor type.
GdkCursorType HitTestCodeToGdkCursorType(int hittest_code) {
switch (hittest_code) {
case HTBOTTOM:
return GDK_BOTTOM_SIDE;
case HTBOTTOMLEFT:
return GDK_BOTTOM_LEFT_CORNER;
case HTBOTTOMRIGHT:
case HTGROWBOX:
return GDK_BOTTOM_RIGHT_CORNER;
case HTLEFT:
return GDK_LEFT_SIDE;
case HTRIGHT:
return GDK_RIGHT_SIDE;
case HTTOP:
return GDK_TOP_SIDE;
case HTTOPLEFT:
return GDK_TOP_LEFT_CORNER;
case HTTOPRIGHT:
return GDK_TOP_RIGHT_CORNER;
default:
break;
}
// Default to something defaultish.
return GDK_LEFT_PTR;
}
} // namespace } // namespace
// During drag and drop GTK sends a drag-leave during a drop. This means we // During drag and drop GTK sends a drag-leave during a drop. This means we
...@@ -702,6 +759,8 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) { ...@@ -702,6 +759,8 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
G_CALLBACK(&OnMapThunk), this); G_CALLBACK(&OnMapThunk), this);
g_signal_connect(widget_, "hide", g_signal_connect(widget_, "hide",
G_CALLBACK(&OnHideThunk), this); G_CALLBACK(&OnHideThunk), this);
g_signal_connect(widget_, "configure-event",
G_CALLBACK(&OnConfigureEventThunk), this);
// Views/FocusManager (re)sets the focus to the root window, // Views/FocusManager (re)sets the focus to the root window,
// so we need to connect signal handlers to the gtk window. // so we need to connect signal handlers to the gtk window.
...@@ -914,6 +973,10 @@ void NativeWidgetGtk::SetAccessibleRole(ui::AccessibilityTypes::Role role) { ...@@ -914,6 +973,10 @@ void NativeWidgetGtk::SetAccessibleRole(ui::AccessibilityTypes::Role role) {
void NativeWidgetGtk::SetAccessibleState(ui::AccessibilityTypes::State state) { void NativeWidgetGtk::SetAccessibleState(ui::AccessibilityTypes::State state) {
} }
void NativeWidgetGtk::BecomeModal() {
gtk_window_set_modal(GetNativeWindow(), true);
}
gfx::Rect NativeWidgetGtk::GetWindowScreenBounds() const { gfx::Rect NativeWidgetGtk::GetWindowScreenBounds() const {
// Client == Window bounds on Gtk. // Client == Window bounds on Gtk.
return GetClientAreaScreenBounds(); return GetClientAreaScreenBounds();
...@@ -1207,6 +1270,20 @@ void NativeWidgetGtk::OnSizeAllocate(GtkWidget* widget, ...@@ -1207,6 +1270,20 @@ void NativeWidgetGtk::OnSizeAllocate(GtkWidget* widget,
return; return;
size_ = new_size; size_ = new_size;
delegate_->OnNativeWidgetSizeChanged(size_); delegate_->OnNativeWidgetSizeChanged(size_);
if (GetWidget()->non_client_view()) {
// The Window's NonClientView may provide a custom shape for the Window.
gfx::Path window_mask;
GetWidget()->non_client_view()->GetWindowMask(gfx::Size(allocation->width,
allocation->height),
&window_mask);
GdkRegion* mask_region = window_mask.CreateNativeRegion();
gdk_window_shape_combine_region(GetNativeView()->window, mask_region, 0, 0);
if (mask_region)
gdk_region_destroy(mask_region);
SaveWindowPosition();
}
} }
gboolean NativeWidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { gboolean NativeWidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) {
...@@ -1349,6 +1426,8 @@ gboolean NativeWidgetGtk::OnEnterNotify(GtkWidget* widget, ...@@ -1349,6 +1426,8 @@ gboolean NativeWidgetGtk::OnEnterNotify(GtkWidget* widget,
gboolean NativeWidgetGtk::OnLeaveNotify(GtkWidget* widget, gboolean NativeWidgetGtk::OnLeaveNotify(GtkWidget* widget,
GdkEventCrossing* event) { GdkEventCrossing* event) {
gdk_window_set_cursor(widget->window, gfx::GetCursor(GDK_LEFT_PTR));
GetWidget()->ResetLastMouseMoveFlag(); GetWidget()->ResetLastMouseMoveFlag();
if (!HasMouseCapture() && !GetWidget()->is_mouse_button_pressed_) { if (!HasMouseCapture() && !GetWidget()->is_mouse_button_pressed_) {
...@@ -1360,6 +1439,20 @@ gboolean NativeWidgetGtk::OnLeaveNotify(GtkWidget* widget, ...@@ -1360,6 +1439,20 @@ gboolean NativeWidgetGtk::OnLeaveNotify(GtkWidget* widget,
gboolean NativeWidgetGtk::OnMotionNotify(GtkWidget* widget, gboolean NativeWidgetGtk::OnMotionNotify(GtkWidget* widget,
GdkEventMotion* event) { GdkEventMotion* event) {
if (GetWidget()->non_client_view()) {
GdkEventMotion transformed_event = *event;
TransformEvent(&transformed_event);
gfx::Point translated_location(transformed_event.x, transformed_event.y);
// Update the cursor for the screen edge.
int hittest_code =
GetWidget()->non_client_view()->NonClientHitTest(translated_location);
if (hittest_code != HTCLIENT) {
GdkCursorType cursor_type = HitTestCodeToGdkCursorType(hittest_code);
gdk_window_set_cursor(widget->window, gfx::GetCursor(cursor_type));
}
}
MouseEvent mouse_event(TransformEvent(event)); MouseEvent mouse_event(TransformEvent(event));
delegate_->OnMouseEvent(mouse_event); delegate_->OnMouseEvent(mouse_event);
return true; return true;
...@@ -1367,6 +1460,55 @@ gboolean NativeWidgetGtk::OnMotionNotify(GtkWidget* widget, ...@@ -1367,6 +1460,55 @@ gboolean NativeWidgetGtk::OnMotionNotify(GtkWidget* widget,
gboolean NativeWidgetGtk::OnButtonPress(GtkWidget* widget, gboolean NativeWidgetGtk::OnButtonPress(GtkWidget* widget,
GdkEventButton* event) { GdkEventButton* event) {
if (GetWidget()->non_client_view()) {
GdkEventButton transformed_event = *event;
MouseEvent mouse_event(TransformEvent(&transformed_event));
int hittest_code = GetWidget()->non_client_view()->NonClientHitTest(
mouse_event.location());
switch (hittest_code) {
case HTCAPTION: {
// Start dragging if the mouse event is a single click and *not* a right
// click. If it is a right click, then pass it through to
// NativeWidgetGtk::OnButtonPress so that View class can show
// ContextMenu upon a mouse release event. We only start drag on single
// clicks as we get a crash in Gtk on double/triple clicks.
if (event->type == GDK_BUTTON_PRESS &&
!mouse_event.IsOnlyRightMouseButton()) {
gfx::Point screen_point(event->x, event->y);
View::ConvertPointToScreen(GetWidget()->GetRootView(), &screen_point);
gtk_window_begin_move_drag(GetNativeWindow(), event->button,
screen_point.x(), screen_point.y(),
event->time);
return TRUE;
}
break;
}
case HTBOTTOM:
case HTBOTTOMLEFT:
case HTBOTTOMRIGHT:
case HTGROWBOX:
case HTLEFT:
case HTRIGHT:
case HTTOP:
case HTTOPLEFT:
case HTTOPRIGHT: {
gfx::Point screen_point(event->x, event->y);
View::ConvertPointToScreen(GetWidget()->GetRootView(), &screen_point);
// TODO(beng): figure out how to get a good minimum size.
gtk_widget_set_size_request(GetNativeView(), 100, 100);
gtk_window_begin_resize_drag(GetNativeWindow(),
HitTestCodeToGDKWindowEdge(hittest_code),
event->button, screen_point.x(),
screen_point.y(), event->time);
return TRUE;
}
default:
// Everything else falls into standard client event handling...
break;
}
}
if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) { if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
// The sequence for double clicks is press, release, press, 2press, release. // The sequence for double clicks is press, release, press, 2press, release.
// This means that at the time we get the second 'press' we don't know // This means that at the time we get the second 'press' we don't know
...@@ -1508,10 +1650,20 @@ void NativeWidgetGtk::OnHide(GtkWidget* widget) { ...@@ -1508,10 +1650,20 @@ void NativeWidgetGtk::OnHide(GtkWidget* widget) {
gboolean NativeWidgetGtk::OnWindowStateEvent(GtkWidget* widget, gboolean NativeWidgetGtk::OnWindowStateEvent(GtkWidget* widget,
GdkEventWindowState* event) { GdkEventWindowState* event) {
if (GetWidget()->non_client_view() &&
!(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)) {
SaveWindowPosition();
}
window_state_ = event->new_window_state; window_state_ = event->new_window_state;
return FALSE; return FALSE;
} }
gboolean NativeWidgetGtk::OnConfigureEvent(GtkWidget* widget,
GdkEventConfigure* event) {
SaveWindowPosition();
return FALSE;
}
void NativeWidgetGtk::HandleXGrabBroke() { void NativeWidgetGtk::HandleXGrabBroke() {
} }
...@@ -1807,6 +1959,17 @@ void NativeWidgetGtk::DrawTransparentBackground(GtkWidget* widget, ...@@ -1807,6 +1959,17 @@ void NativeWidgetGtk::DrawTransparentBackground(GtkWidget* widget,
cairo_destroy(cr); cairo_destroy(cr);
} }
void NativeWidgetGtk::SaveWindowPosition() {
// The delegate may have gone away on us.
if (!GetWidget()->widget_delegate())
return;
bool maximized = window_state_ & GDK_WINDOW_STATE_MAXIMIZED;
GetWidget()->widget_delegate()->SaveWindowPlacement(
GetWidget()->GetWindowScreenBounds(),
maximized);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Widget, public: // Widget, public:
......
...@@ -188,6 +188,7 @@ class NativeWidgetGtk : public NativeWidget, ...@@ -188,6 +188,7 @@ class NativeWidgetGtk : public NativeWidget,
virtual void SetAccessibleName(const std::wstring& name) OVERRIDE; virtual void SetAccessibleName(const std::wstring& name) OVERRIDE;
virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE; virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE;
virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE;
virtual void BecomeModal() OVERRIDE;
virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE;
virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE;
virtual gfx::Rect GetRestoredBounds() const OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
...@@ -282,6 +283,8 @@ class NativeWidgetGtk : public NativeWidget, ...@@ -282,6 +283,8 @@ class NativeWidgetGtk : public NativeWidget,
CHROMEGTK_CALLBACK_0(NativeWidgetGtk, void, OnHide); CHROMEGTK_CALLBACK_0(NativeWidgetGtk, void, OnHide);
CHROMEGTK_CALLBACK_1(NativeWidgetGtk, gboolean, OnWindowStateEvent, CHROMEGTK_CALLBACK_1(NativeWidgetGtk, gboolean, OnWindowStateEvent,
GdkEventWindowState*); GdkEventWindowState*);
CHROMEGTK_CALLBACK_1(NativeWidgetGtk, gboolean, OnConfigureEvent,
GdkEventConfigure*);
// Invoked when the widget is destroyed and right before the object // Invoked when the widget is destroyed and right before the object
// destruction. Useful for overriding. // destruction. Useful for overriding.
...@@ -345,6 +348,9 @@ class NativeWidgetGtk : public NativeWidget, ...@@ -345,6 +348,9 @@ class NativeWidgetGtk : public NativeWidget,
static void DrawTransparentBackground(GtkWidget* widget, static void DrawTransparentBackground(GtkWidget* widget,
GdkEventExpose* event); GdkEventExpose* event);
// Asks the delegate if any to save the window's location and size.
void SaveWindowPosition();
// A delegate implementation that handles events received here. // A delegate implementation that handles events received here.
// See class documentation for Widget in widget.h for a note about ownership. // See class documentation for Widget in widget.h for a note about ownership.
internal::NativeWidgetDelegate* delegate_; internal::NativeWidgetDelegate* delegate_;
......
...@@ -168,6 +168,10 @@ void NativeWidgetViews::SetAccessibleState( ...@@ -168,6 +168,10 @@ void NativeWidgetViews::SetAccessibleState(
ui::AccessibilityTypes::State state) { ui::AccessibilityTypes::State state) {
} }
void NativeWidgetViews::BecomeModal() {
NOTIMPLEMENTED();
}
gfx::AcceleratedWidget NativeWidgetViews::GetAcceleratedWidget() { gfx::AcceleratedWidget NativeWidgetViews::GetAcceleratedWidget() {
// TODO(sky): // TODO(sky):
return gfx::kNullAcceleratedWidget; return gfx::kNullAcceleratedWidget;
......
...@@ -69,6 +69,7 @@ class NativeWidgetViews : public NativeWidget { ...@@ -69,6 +69,7 @@ class NativeWidgetViews : public NativeWidget {
virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE; virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE;
virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
virtual void BecomeModal() OVERRIDE;
virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE;
virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE;
virtual gfx::Rect GetRestoredBounds() const OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
......
This diff is collapsed.
...@@ -30,6 +30,7 @@ class ViewProp; ...@@ -30,6 +30,7 @@ class ViewProp;
namespace gfx { namespace gfx {
class CanvasSkia; class CanvasSkia;
class Font;
class Rect; class Rect;
} }
...@@ -88,6 +89,9 @@ class NativeWidgetWin : public ui::WindowImpl, ...@@ -88,6 +89,9 @@ class NativeWidgetWin : public ui::WindowImpl,
// enabled. // enabled.
static bool IsAeroGlassEnabled(); static bool IsAeroGlassEnabled();
// Returns the system set window title font.
static gfx::Font GetWindowTitleFont();
// Show the window with the specified show command. // Show the window with the specified show command.
void Show(int show_state); void Show(int show_state);
...@@ -212,6 +216,7 @@ class NativeWidgetWin : public ui::WindowImpl, ...@@ -212,6 +216,7 @@ class NativeWidgetWin : public ui::WindowImpl,
virtual void SetAccessibleName(const std::wstring& name) OVERRIDE; virtual void SetAccessibleName(const std::wstring& name) OVERRIDE;
virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE; virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE;
virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE;
virtual void BecomeModal() OVERRIDE;
virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE;
virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE;
virtual gfx::Rect GetRestoredBounds() const OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
...@@ -513,6 +518,11 @@ class NativeWidgetWin : public ui::WindowImpl, ...@@ -513,6 +518,11 @@ class NativeWidgetWin : public ui::WindowImpl,
// flicker. // flicker.
LRESULT CallDefaultNCActivateHandler(BOOL active); LRESULT CallDefaultNCActivateHandler(BOOL active);
// Stops ignoring SetWindowPos() requests (see below).
void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; }
void RestoreEnabledIfNecessary();
// Overridden from NativeWidget. // Overridden from NativeWidget.
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
...@@ -625,6 +635,28 @@ class NativeWidgetWin : public ui::WindowImpl, ...@@ -625,6 +635,28 @@ class NativeWidgetWin : public ui::WindowImpl,
// The window styles of the window before updates were locked. // The window styles of the window before updates were locked.
DWORD saved_window_style_; DWORD saved_window_style_;
// When true, this flag makes us discard incoming SetWindowPos() requests that
// only change our position/size. (We still allow changes to Z-order,
// activation, etc.)
bool ignore_window_pos_changes_;
// The following factory is used to ignore SetWindowPos() calls for short time
// periods.
ScopedRunnableMethodFactory<NativeWidgetWin> ignore_pos_changes_factory_;
// The last-seen monitor containing us, and its rect and work area. These are
// used to catch updates to the rect and work area and react accordingly.
HMONITOR last_monitor_;
gfx::Rect last_monitor_rect_, last_work_area_;
// Set to true when the user presses the right mouse button on the caption
// area. We need this so we can correctly show the context menu on mouse-up.
bool is_right_mouse_pressed_on_caption_;
// Whether all ancestors have been enabled. This is only used if is_modal_ is
// true.
bool restored_enabled_;
DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin); DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin);
}; };
......
...@@ -44,7 +44,7 @@ class NativeWidgetWinTest : public testing::Test { ...@@ -44,7 +44,7 @@ class NativeWidgetWinTest : public testing::Test {
NativeWidgetWin* NativeWidgetWinTest::CreateNativeWidgetWin() { NativeWidgetWin* NativeWidgetWinTest::CreateNativeWidgetWin() {
scoped_ptr<Widget> widget(new Widget); scoped_ptr<Widget> widget(new Widget);
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(50, 50, 650, 650); params.bounds = gfx::Rect(50, 50, 650, 650);
widget->Init(params); widget->Init(params);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/compositor.h"
#include "views/focus/view_storage.h" #include "views/focus/view_storage.h"
#include "views/ime/input_method.h" #include "views/ime/input_method.h"
...@@ -98,7 +100,9 @@ Widget::Widget() ...@@ -98,7 +100,9 @@ Widget::Widget()
is_secondary_widget_(true), is_secondary_widget_(true),
frame_type_(FRAME_TYPE_DEFAULT), frame_type_(FRAME_TYPE_DEFAULT),
disable_inactive_rendering_(false), disable_inactive_rendering_(false),
widget_closed_(false) { widget_closed_(false),
saved_maximized_state_(false),
minimum_size_(100, 100) {
} }
Widget::~Widget() { Widget::~Widget() {
...@@ -125,6 +129,25 @@ Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) { ...@@ -125,6 +129,25 @@ Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {
return native_widget ? native_widget->GetWidget() : NULL; return native_widget ? native_widget->GetWidget() : NULL;
} }
// static
int Widget::GetLocalizedContentsWidth(int col_resource_id) {
return ui::GetLocalizedContentsWidthForFont(col_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
}
// static
int Widget::GetLocalizedContentsHeight(int row_resource_id) {
return ui::GetLocalizedContentsHeightForFont(row_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
}
// static
gfx::Size Widget::GetLocalizedContentsSize(int col_resource_id,
int row_resource_id) {
return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
GetLocalizedContentsHeight(row_resource_id));
}
void Widget::Init(const InitParams& params) { void Widget::Init(const InitParams& params) {
widget_delegate_ = widget_delegate_ =
params.delegate ? params.delegate : new DefaultWidgetDelegate; params.delegate ? params.delegate : new DefaultWidgetDelegate;
...@@ -144,6 +167,8 @@ void Widget::Init(const InitParams& params) { ...@@ -144,6 +167,8 @@ void Widget::Init(const InitParams& params) {
// NonClientView to the RootView. This will cause everything to be parented. // NonClientView to the RootView. This will cause everything to be parented.
non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
SetContentsView(non_client_view_); SetContentsView(non_client_view_);
SetInitialBounds(params.bounds);
UpdateWindowTitle();
} }
} }
...@@ -284,7 +309,17 @@ void Widget::EnableClose(bool enable) { ...@@ -284,7 +309,17 @@ void Widget::EnableClose(bool enable) {
} }
void Widget::Show() { void Widget::Show() {
native_widget_->Show(); if (non_client_view_) {
native_widget_->ShowNativeWidget(
saved_maximized_state_ ? NativeWidget::SHOW_MAXIMIZED
: NativeWidget::SHOW_RESTORED);
// |saved_maximized_state_| only applies the first time the window is shown.
// If we don't reset the value the window will be shown maximized every time
// it is subsequently shown after being hidden.
saved_maximized_state_ = false;
} else {
native_widget_->Show();
}
} }
void Widget::Hide() { void Widget::Hide() {
...@@ -433,11 +468,12 @@ void Widget::ResetLastMouseMoveFlag() { ...@@ -433,11 +468,12 @@ void Widget::ResetLastMouseMoveFlag() {
} }
void Widget::UpdateWindowTitle() { void Widget::UpdateWindowTitle() {
if (non_client_view_) { if (!non_client_view_)
// If the non-client view is rendering its own title, it'll need to relayout return;
// now.
non_client_view_->Layout(); // If the non-client view is rendering its own title, it'll need to relayout
} // now.
non_client_view_->Layout();
// Update the native frame's text. We do this regardless of whether or not // Update the native frame's text. We do this regardless of whether or not
// the native frame is being used, since this also updates the taskbar, etc. // the native frame is being used, since this also updates the taskbar, etc.
...@@ -524,6 +560,14 @@ void Widget::NotifyAccessibilityEvent( ...@@ -524,6 +560,14 @@ void Widget::NotifyAccessibilityEvent(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Widget, NativeWidgetDelegate implementation: // Widget, NativeWidgetDelegate implementation:
bool Widget::IsModal() const {
return widget_delegate_->IsModal();
}
bool Widget::IsDialogBox() const {
return !!widget_delegate_->AsDialogDelegate();
}
bool Widget::CanActivate() const { bool Widget::CanActivate() const {
return widget_delegate_->CanActivate(); return widget_delegate_->CanActivate();
} }
...@@ -570,6 +614,9 @@ void Widget::OnNativeWidgetCreated() { ...@@ -570,6 +614,9 @@ void Widget::OnNativeWidgetCreated() {
widget_delegate_->GetAccessibleWindowRole()); widget_delegate_->GetAccessibleWindowRole());
native_widget_->SetAccessibleState( native_widget_->SetAccessibleState(
widget_delegate_->GetAccessibleWindowState()); widget_delegate_->GetAccessibleWindowState());
if (widget_delegate_->IsModal())
native_widget_->BecomeModal();
} }
void Widget::OnNativeWidgetDestroying() { void Widget::OnNativeWidgetDestroying() {
...@@ -780,6 +827,55 @@ void Widget::SaveWindowPosition() { ...@@ -780,6 +827,55 @@ void Widget::SaveWindowPosition() {
widget_delegate_->SaveWindowPlacement(bounds, maximized); widget_delegate_->SaveWindowPlacement(bounds, maximized);
} }
void Widget::SetInitialBounds(const gfx::Rect& bounds) {
if (!non_client_view_)
return;
// First we obtain the window's saved show-style and store it. We need to do
// this here, rather than in Show() because by the time Show() is called,
// the window's size will have been reset (below) and the saved maximized
// state will have been lost. Sadly there's no way to tell on Windows when
// a window is restored from maximized state, so we can't more accurately
// track maximized state independently of sizing information.
widget_delegate_->GetSavedMaximizedState(
&saved_maximized_state_);
// Restore the window's placement from the controller.
gfx::Rect saved_bounds = bounds;
if (widget_delegate_->GetSavedWindowBounds(&saved_bounds)) {
if (!widget_delegate_->ShouldRestoreWindowSize()) {
saved_bounds.set_size(non_client_view_->GetPreferredSize());
} else {
// Make sure the bounds are at least the minimum size.
if (saved_bounds.width() < minimum_size_.width()) {
saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
saved_bounds.right() + minimum_size_.width() -
saved_bounds.width(),
saved_bounds.bottom());
}
if (saved_bounds.height() < minimum_size_.height()) {
saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
saved_bounds.right(),
saved_bounds.bottom() + minimum_size_.height() -
saved_bounds.height());
}
}
// Widget's SetBounds method does not further modify the bounds that are
// passed to it.
SetBounds(saved_bounds);
} else {
if (bounds.IsEmpty()) {
// No initial bounds supplied, so size the window to its content and
// center over its parent.
native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
} else {
// Use the supplied initial bounds.
SetBoundsConstrained(bounds, NULL);
}
}
}
} // namespace views } // namespace views
...@@ -93,7 +93,8 @@ class Widget : public internal::NativeWidgetDelegate, ...@@ -93,7 +93,8 @@ class Widget : public internal::NativeWidgetDelegate,
struct InitParams { struct InitParams {
enum Type { enum Type {
TYPE_WINDOW, // A Window, like a frame window. TYPE_WINDOW, // A decorated Window, like a frame window.
// Widgets of TYPE_WINDOW will have a NonClientView.
TYPE_WINDOW_FRAMELESS, TYPE_WINDOW_FRAMELESS,
// An undecorated Window. // An undecorated Window.
TYPE_CONTROL, // A control, like a button. TYPE_CONTROL, // A control, like a button.
...@@ -166,6 +167,17 @@ class Widget : public internal::NativeWidgetDelegate, ...@@ -166,6 +167,17 @@ class Widget : public internal::NativeWidgetDelegate,
// Passes through to NativeWidget::GetWidgetForNativeView(). // Passes through to NativeWidget::GetWidgetForNativeView().
static Widget* GetWidgetForNativeView(gfx::NativeView native_view); static Widget* GetWidgetForNativeView(gfx::NativeView native_view);
// Returns the preferred size of the contents view of this window based on
// its localized size data. The width in cols is held in a localized string
// resource identified by |col_resource_id|, the height in the same fashion.
// TODO(beng): This should eventually live somewhere else, probably closer to
// ClientView.
static int GetLocalizedContentsWidth(int col_resource_id);
static int GetLocalizedContentsHeight(int row_resource_id);
static gfx::Size GetLocalizedContentsSize(int col_resource_id,
int row_resource_id);
void Init(const InitParams& params); void Init(const InitParams& params);
// Unconverted methods ------------------------------------------------------- // Unconverted methods -------------------------------------------------------
...@@ -447,6 +459,8 @@ class Widget : public internal::NativeWidgetDelegate, ...@@ -447,6 +459,8 @@ class Widget : public internal::NativeWidgetDelegate,
virtual const Window* AsWindow() const; virtual const Window* AsWindow() const;
// Overridden from NativeWidgetDelegate: // Overridden from NativeWidgetDelegate:
virtual bool IsModal() const OVERRIDE;
virtual bool IsDialogBox() const OVERRIDE;
virtual bool CanActivate() const OVERRIDE; virtual bool CanActivate() const OVERRIDE;
virtual bool IsInactiveRenderingDisabled() const OVERRIDE; virtual bool IsInactiveRenderingDisabled() const OVERRIDE;
virtual void EnableInactiveRendering() OVERRIDE; virtual void EnableInactiveRendering() OVERRIDE;
...@@ -518,6 +532,9 @@ class Widget : public internal::NativeWidgetDelegate, ...@@ -518,6 +532,9 @@ class Widget : public internal::NativeWidgetDelegate,
// window delegate. // window delegate.
void SaveWindowPosition(); void SaveWindowPosition();
// Sizes and positions the window just after it is created.
void SetInitialBounds(const gfx::Rect& bounds);
NativeWidget* native_widget_; NativeWidget* native_widget_;
// Non-owned pointer to the Widget's delegate. May be NULL if no delegate is // Non-owned pointer to the Widget's delegate. May be NULL if no delegate is
...@@ -568,6 +585,13 @@ class Widget : public internal::NativeWidgetDelegate, ...@@ -568,6 +585,13 @@ class Widget : public internal::NativeWidgetDelegate,
// Set to true if the widget is in the process of closing. // Set to true if the widget is in the process of closing.
bool widget_closed_; bool widget_closed_;
// The saved maximized state for this window. See note in SetInitialBounds
// that explains why we save this.
bool saved_maximized_state_;
// The smallest size the window can be.
gfx::Size minimum_size_;
DISALLOW_COPY_AND_ASSIGN(Widget); DISALLOW_COPY_AND_ASSIGN(Widget);
}; };
......
...@@ -44,9 +44,6 @@ class NativeWindow { ...@@ -44,9 +44,6 @@ class NativeWindow {
protected: protected:
friend class Window; friend class Window;
// Makes the NativeWindow modal.
virtual void BecomeModal() = 0;
}; };
} // namespace views } // namespace views
......
...@@ -23,15 +23,6 @@ class NativeWindowDelegate { ...@@ -23,15 +23,6 @@ class NativeWindowDelegate {
public: public:
virtual ~NativeWindowDelegate() {} virtual ~NativeWindowDelegate() {}
// Returns true if the window is modal.
virtual bool IsModal() const = 0;
// Returns true if the window is a dialog box.
virtual bool IsDialogBox() const = 0;
// Called just after the NativeWindow has been created.
virtual void OnNativeWindowCreated(const gfx::Rect& bounds) = 0;
// //
virtual Window* AsWindow() = 0; virtual Window* AsWindow() = 0;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "views/events/event.h" #include "views/events/event.h"
...@@ -15,185 +14,17 @@ ...@@ -15,185 +14,17 @@
#include "views/window/non_client_view.h" #include "views/window/non_client_view.h"
#include "views/window/window_delegate.h" #include "views/window/window_delegate.h"
namespace {
// Converts a Windows-style hit test result code into a GDK window edge.
GdkWindowEdge HitTestCodeToGDKWindowEdge(int hittest_code) {
switch (hittest_code) {
case HTBOTTOM:
return GDK_WINDOW_EDGE_SOUTH;
case HTBOTTOMLEFT:
return GDK_WINDOW_EDGE_SOUTH_WEST;
case HTBOTTOMRIGHT:
case HTGROWBOX:
return GDK_WINDOW_EDGE_SOUTH_EAST;
case HTLEFT:
return GDK_WINDOW_EDGE_WEST;
case HTRIGHT:
return GDK_WINDOW_EDGE_EAST;
case HTTOP:
return GDK_WINDOW_EDGE_NORTH;
case HTTOPLEFT:
return GDK_WINDOW_EDGE_NORTH_WEST;
case HTTOPRIGHT:
return GDK_WINDOW_EDGE_NORTH_EAST;
default:
NOTREACHED();
break;
}
// Default to something defaultish.
return HitTestCodeToGDKWindowEdge(HTGROWBOX);
}
// Converts a Windows-style hit test result code into a GDK cursor type.
GdkCursorType HitTestCodeToGdkCursorType(int hittest_code) {
switch (hittest_code) {
case HTBOTTOM:
return GDK_BOTTOM_SIDE;
case HTBOTTOMLEFT:
return GDK_BOTTOM_LEFT_CORNER;
case HTBOTTOMRIGHT:
case HTGROWBOX:
return GDK_BOTTOM_RIGHT_CORNER;
case HTLEFT:
return GDK_LEFT_SIDE;
case HTRIGHT:
return GDK_RIGHT_SIDE;
case HTTOP:
return GDK_TOP_SIDE;
case HTTOPLEFT:
return GDK_TOP_LEFT_CORNER;
case HTTOPRIGHT:
return GDK_TOP_RIGHT_CORNER;
default:
break;
}
// Default to something defaultish.
return GDK_LEFT_PTR;
}
} // namespace
namespace views { namespace views {
NativeWindowGtk::NativeWindowGtk(internal::NativeWindowDelegate* delegate) NativeWindowGtk::NativeWindowGtk(internal::NativeWindowDelegate* delegate)
: NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), : NativeWidgetGtk(delegate->AsNativeWidgetDelegate()),
delegate_(delegate), delegate_(delegate) {
window_closed_(false) {
is_window_ = true; is_window_ = true;
} }
NativeWindowGtk::~NativeWindowGtk() { NativeWindowGtk::~NativeWindowGtk() {
} }
////////////////////////////////////////////////////////////////////////////////
// NativeWindowGtk, NativeWidgetGtk overrides:
gboolean NativeWindowGtk::OnButtonPress(GtkWidget* widget,
GdkEventButton* event) {
GdkEventButton transformed_event = *event;
MouseEvent mouse_event(TransformEvent(&transformed_event));
int hittest_code =
GetWindow()->non_client_view()->NonClientHitTest(mouse_event.location());
switch (hittest_code) {
case HTCAPTION: {
// Start dragging if the mouse event is a single click and *not* a right
// click. If it is a right click, then pass it through to
// NativeWidgetGtk::OnButtonPress so that View class can show ContextMenu
// upon a mouse release event. We only start drag on single clicks as we
// get a crash in Gtk on double/triple clicks.
if (event->type == GDK_BUTTON_PRESS &&
!mouse_event.IsOnlyRightMouseButton()) {
gfx::Point screen_point(event->x, event->y);
View::ConvertPointToScreen(GetWindow()->GetRootView(), &screen_point);
gtk_window_begin_move_drag(GetNativeWindow(), event->button,
screen_point.x(), screen_point.y(),
event->time);
return TRUE;
}
break;
}
case HTBOTTOM:
case HTBOTTOMLEFT:
case HTBOTTOMRIGHT:
case HTGROWBOX:
case HTLEFT:
case HTRIGHT:
case HTTOP:
case HTTOPLEFT:
case HTTOPRIGHT: {
gfx::Point screen_point(event->x, event->y);
View::ConvertPointToScreen(GetWindow()->GetRootView(), &screen_point);
// TODO(beng): figure out how to get a good minimum size.
gtk_widget_set_size_request(GetNativeView(), 100, 100);
gtk_window_begin_resize_drag(GetNativeWindow(),
HitTestCodeToGDKWindowEdge(hittest_code),
event->button, screen_point.x(),
screen_point.y(), event->time);
return TRUE;
}
default:
// Everything else falls into standard client event handling...
break;
}
return NativeWidgetGtk::OnButtonPress(widget, event);
}
gboolean NativeWindowGtk::OnConfigureEvent(GtkWidget* widget,
GdkEventConfigure* event) {
SaveWindowPosition();
return FALSE;
}
gboolean NativeWindowGtk::OnMotionNotify(GtkWidget* widget,
GdkEventMotion* event) {
GdkEventMotion transformed_event = *event;
TransformEvent(&transformed_event);
gfx::Point translated_location(transformed_event.x, transformed_event.y);
// Update the cursor for the screen edge.
int hittest_code =
GetWindow()->non_client_view()->NonClientHitTest(translated_location);
if (hittest_code != HTCLIENT) {
GdkCursorType cursor_type = HitTestCodeToGdkCursorType(hittest_code);
gdk_window_set_cursor(widget->window, gfx::GetCursor(cursor_type));
}
return NativeWidgetGtk::OnMotionNotify(widget, event);
}
void NativeWindowGtk::OnSizeAllocate(GtkWidget* widget,
GtkAllocation* allocation) {
NativeWidgetGtk::OnSizeAllocate(widget, allocation);
// The Window's NonClientView may provide a custom shape for the Window.
gfx::Path window_mask;
GetWindow()->non_client_view()->GetWindowMask(gfx::Size(allocation->width,
allocation->height),
&window_mask);
GdkRegion* mask_region = window_mask.CreateNativeRegion();
gdk_window_shape_combine_region(GetNativeView()->window, mask_region, 0, 0);
if (mask_region)
gdk_region_destroy(mask_region);
SaveWindowPosition();
}
gboolean NativeWindowGtk::OnLeaveNotify(GtkWidget* widget,
GdkEventCrossing* event) {
gdk_window_set_cursor(widget->window, gfx::GetCursor(GDK_LEFT_PTR));
return NativeWidgetGtk::OnLeaveNotify(widget, event);
}
void NativeWindowGtk::InitNativeWidget(const Widget::InitParams& params) {
NativeWidgetGtk::InitNativeWidget(params);
g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event",
G_CALLBACK(CallConfigureEvent), this);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeWindowGtk, NativeWindow implementation: // NativeWindowGtk, NativeWindow implementation:
...@@ -205,10 +36,6 @@ const NativeWidget* NativeWindowGtk::AsNativeWidget() const { ...@@ -205,10 +36,6 @@ const NativeWidget* NativeWindowGtk::AsNativeWidget() const {
return this; return this;
} }
void NativeWindowGtk::BecomeModal() {
gtk_window_set_modal(GetNativeWindow(), true);
}
Window* NativeWindowGtk::GetWindow() { Window* NativeWindowGtk::GetWindow() {
return delegate_->AsWindow(); return delegate_->AsWindow();
} }
...@@ -217,37 +44,9 @@ const Window* NativeWindowGtk::GetWindow() const { ...@@ -217,37 +44,9 @@ const Window* NativeWindowGtk::GetWindow() const {
return delegate_->AsWindow(); return delegate_->AsWindow();
} }
////////////////////////////////////////////////////////////////////////////////
// NativeWindowGtk, NativeWidgetGtk overrides:
gboolean NativeWindowGtk::OnWindowStateEvent(GtkWidget* widget,
GdkEventWindowState* event) {
if (!(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN))
SaveWindowPosition();
return NativeWidgetGtk::OnWindowStateEvent(widget, event);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeWindowGtk, private: // NativeWindowGtk, private:
// static
gboolean NativeWindowGtk::CallConfigureEvent(GtkWidget* widget,
GdkEventConfigure* event,
NativeWindowGtk* window_gtk) {
return window_gtk->OnConfigureEvent(widget, event);
}
void NativeWindowGtk::SaveWindowPosition() {
// The delegate may have gone away on us.
if (!GetWindow()->window_delegate())
return;
bool maximized = window_state_ & GDK_WINDOW_STATE_MAXIMIZED;
GetWindow()->window_delegate()->SaveWindowPlacement(
GetWidget()->GetWindowScreenBounds(),
maximized);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeWindow, public: // NativeWindow, public:
......
...@@ -9,21 +9,12 @@ ...@@ -9,21 +9,12 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "views/widget/native_widget_gtk.h" #include "views/widget/native_widget_gtk.h"
#include "views/window/native_window.h" #include "views/window/native_window.h"
#include "views/window/window.h"
namespace gfx {
class Point;
class Size;
};
namespace views { namespace views {
namespace internal { namespace internal {
class NativeWindowDelegate; class NativeWindowDelegate;
} }
class Client;
class WindowDelegate;
// Window implementation for Gtk. // Window implementation for Gtk.
class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow {
public: public:
...@@ -33,52 +24,18 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { ...@@ -33,52 +24,18 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow {
virtual Window* GetWindow() OVERRIDE; virtual Window* GetWindow() OVERRIDE;
virtual const Window* GetWindow() const OVERRIDE; virtual const Window* GetWindow() const OVERRIDE;
// Overridden from NativeWidgetGtk:
virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event);
virtual gboolean OnConfigureEvent(GtkWidget* widget,
GdkEventConfigure* event);
virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event);
virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation);
virtual gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event);
protected: protected:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
// Overridden from NativeWindow: // Overridden from NativeWindow:
virtual NativeWidget* AsNativeWidget() OVERRIDE; virtual NativeWidget* AsNativeWidget() OVERRIDE;
virtual const NativeWidget* AsNativeWidget() const OVERRIDE; virtual const NativeWidget* AsNativeWidget() const OVERRIDE;
virtual void BecomeModal() OVERRIDE;
// Overridden from NativeWidgetGtk:
virtual gboolean OnWindowStateEvent(GtkWidget* widget,
GdkEventWindowState* event) OVERRIDE;
// For the constructor. // For the constructor.
friend class Window; friend class Window;
private: private:
static gboolean CallConfigureEvent(GtkWidget* widget,
GdkEventConfigure* event,
NativeWindowGtk* window_gtk);
// Asks the delegate if any to save the window's location and size.
void SaveWindowPosition();
// A delegate implementation that handles events received here. // A delegate implementation that handles events received here.
internal::NativeWindowDelegate* delegate_; internal::NativeWindowDelegate* delegate_;
// Our window delegate.
WindowDelegate* window_delegate_;
// The View that provides the non-client area of the window (title bar,
// window controls, sizing borders etc). To use an implementation other than
// the default, this class must be subclassed and this value set to the
// desired implementation before calling |Init|.
NonClientView* non_client_view_;
// Set to true if the window is in the process of closing.
bool window_closed_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowGtk); DISALLOW_COPY_AND_ASSIGN(NativeWindowGtk);
}; };
......
This diff is collapsed.
...@@ -8,13 +8,6 @@ ...@@ -8,13 +8,6 @@
#include "views/widget/native_widget_win.h" #include "views/widget/native_widget_win.h"
#include "views/window/native_window.h" #include "views/window/native_window.h"
#include "views/window/window.h"
namespace gfx {
class Font;
class Point;
class Size;
};
namespace views { namespace views {
namespace internal { namespace internal {
...@@ -29,9 +22,6 @@ void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, ...@@ -29,9 +22,6 @@ void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect,
} // namespace internal } // namespace internal
class Client;
class WindowDelegate;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// NativeWindowWin // NativeWindowWin
...@@ -47,9 +37,6 @@ class NativeWindowWin : public NativeWidgetWin, ...@@ -47,9 +37,6 @@ class NativeWindowWin : public NativeWidgetWin,
explicit NativeWindowWin(internal::NativeWindowDelegate* delegate); explicit NativeWindowWin(internal::NativeWindowDelegate* delegate);
virtual ~NativeWindowWin(); virtual ~NativeWindowWin();
// Returns the system set window title font.
static gfx::Font GetWindowTitleFont();
// Overridden from NativeWindow: // Overridden from NativeWindow:
virtual Window* GetWindow() OVERRIDE; virtual Window* GetWindow() OVERRIDE;
virtual const Window* GetWindow() const OVERRIDE; virtual const Window* GetWindow() const OVERRIDE;
...@@ -57,62 +44,14 @@ class NativeWindowWin : public NativeWidgetWin, ...@@ -57,62 +44,14 @@ class NativeWindowWin : public NativeWidgetWin,
protected: protected:
friend Window; friend Window;
// Overridden from NativeWidgetWin:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual void OnDestroy() OVERRIDE;
virtual LRESULT OnMouseRange(UINT message,
WPARAM w_param,
LPARAM l_param) OVERRIDE;
LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); // Don't override.
virtual void OnNCPaint(HRGN rgn) OVERRIDE;
virtual void OnWindowPosChanging(WINDOWPOS* window_pos) OVERRIDE;
// Overridden from NativeWindow: // Overridden from NativeWindow:
virtual NativeWidget* AsNativeWidget() OVERRIDE; virtual NativeWidget* AsNativeWidget() OVERRIDE;
virtual const NativeWidget* AsNativeWidget() const OVERRIDE; virtual const NativeWidget* AsNativeWidget() const OVERRIDE;
virtual void BecomeModal() OVERRIDE;
private: private:
// If necessary, enables all ancestors.
void RestoreEnabledIfNecessary();
// Calculate the appropriate window styles for this window.
DWORD CalculateWindowStyle();
DWORD CalculateWindowExStyle();
// Stops ignoring SetWindowPos() requests (see below).
void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; }
// Update accessibility information via our WindowDelegate.
void UpdateAccessibleName(std::wstring& accessible_name);
void UpdateAccessibleRole();
void UpdateAccessibleState();
// A delegate implementation that handles events received here. // A delegate implementation that handles events received here.
internal::NativeWindowDelegate* delegate_; internal::NativeWindowDelegate* delegate_;
// Whether all ancestors have been enabled. This is only used if is_modal_ is
// true.
bool restored_enabled_;
// When true, this flag makes us discard incoming SetWindowPos() requests that
// only change our position/size. (We still allow changes to Z-order,
// activation, etc.)
bool ignore_window_pos_changes_;
// The following factory is used to ignore SetWindowPos() calls for short time
// periods.
ScopedRunnableMethodFactory<NativeWindowWin> ignore_pos_changes_factory_;
// Set to true when the user presses the right mouse button on the caption
// area. We need this so we can correctly show the context menu on mouse-up.
bool is_right_mouse_pressed_on_caption_;
// The last-seen monitor containing us, and its rect and work area. These are
// used to catch updates to the rect and work area and react accordingly.
HMONITOR last_monitor_;
gfx::Rect last_monitor_rect_, last_work_area_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowWin); DISALLOW_COPY_AND_ASSIGN(NativeWindowWin);
}; };
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
...@@ -29,9 +27,7 @@ Window::InitParams::InitParams(WindowDelegate* window_delegate) ...@@ -29,9 +27,7 @@ Window::InitParams::InitParams(WindowDelegate* window_delegate)
} }
Window::Window() Window::Window()
: native_window_(NULL), : native_window_(NULL) {
saved_maximized_state_(false),
minimum_size_(100, 100) {
} }
Window::~Window() { Window::~Window() {
...@@ -52,25 +48,6 @@ Window* Window::CreateChromeWindow(gfx::NativeWindow parent, ...@@ -52,25 +48,6 @@ Window* Window::CreateChromeWindow(gfx::NativeWindow parent,
return window; return window;
} }
// static
int Window::GetLocalizedContentsWidth(int col_resource_id) {
return ui::GetLocalizedContentsWidthForFont(col_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
}
// static
int Window::GetLocalizedContentsHeight(int row_resource_id) {
return ui::GetLocalizedContentsHeightForFont(row_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
}
// static
gfx::Size Window::GetLocalizedContentsSize(int col_resource_id,
int row_resource_id) {
return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
GetLocalizedContentsHeight(row_resource_id));
}
void Window::InitWindow(const InitParams& params) { void Window::InitWindow(const InitParams& params) {
native_window_ = native_window_ =
params.native_window ? params.native_window params.native_window ? params.native_window
...@@ -82,22 +59,11 @@ void Window::InitWindow(const InitParams& params) { ...@@ -82,22 +59,11 @@ void Window::InitWindow(const InitParams& params) {
modified_params.widget_init_params.native_widget = modified_params.widget_init_params.native_widget =
native_window_->AsNativeWidget(); native_window_->AsNativeWidget();
Init(modified_params.widget_init_params); Init(modified_params.widget_init_params);
OnNativeWindowCreated(modified_params.widget_init_params.bounds);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Window, Widget overrides: // Window, Widget overrides:
void Window::Show() {
native_window_->AsNativeWidget()->ShowNativeWidget(
saved_maximized_state_ ? NativeWidget::SHOW_MAXIMIZED
: NativeWidget::SHOW_RESTORED);
// |saved_maximized_state_| only applies the first time the window is shown.
// If we don't reset the value the window will be shown maximized every time
// it is subsequently shown after being hidden.
saved_maximized_state_ = false;
}
Window* Window::AsWindow() { Window* Window::AsWindow() {
return this; return this;
} }
...@@ -109,75 +75,8 @@ const Window* Window::AsWindow() const { ...@@ -109,75 +75,8 @@ const Window* Window::AsWindow() const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Window, internal::NativeWindowDelegate implementation: // Window, internal::NativeWindowDelegate implementation:
bool Window::IsModal() const {
return widget_delegate()->IsModal();
}
bool Window::IsDialogBox() const {
return !!widget_delegate()->AsDialogDelegate();
}
void Window::OnNativeWindowCreated(const gfx::Rect& bounds) {
if (widget_delegate()->IsModal())
native_window_->BecomeModal();
UpdateWindowTitle();
SetInitialBounds(bounds);
}
internal::NativeWidgetDelegate* Window::AsNativeWidgetDelegate() { internal::NativeWidgetDelegate* Window::AsNativeWidgetDelegate() {
return this; return this;
} }
////////////////////////////////////////////////////////////////////////////////
// Window, private:
void Window::SetInitialBounds(const gfx::Rect& bounds) {
// First we obtain the window's saved show-style and store it. We need to do
// this here, rather than in Show() because by the time Show() is called,
// the window's size will have been reset (below) and the saved maximized
// state will have been lost. Sadly there's no way to tell on Windows when
// a window is restored from maximized state, so we can't more accurately
// track maximized state independently of sizing information.
widget_delegate()->GetSavedMaximizedState(
&saved_maximized_state_);
// Restore the window's placement from the controller.
gfx::Rect saved_bounds = bounds;
if (widget_delegate()->GetSavedWindowBounds(&saved_bounds)) {
if (!widget_delegate()->ShouldRestoreWindowSize()) {
saved_bounds.set_size(non_client_view()->GetPreferredSize());
} else {
// Make sure the bounds are at least the minimum size.
if (saved_bounds.width() < minimum_size_.width()) {
saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
saved_bounds.right() + minimum_size_.width() -
saved_bounds.width(),
saved_bounds.bottom());
}
if (saved_bounds.height() < minimum_size_.height()) {
saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
saved_bounds.right(),
saved_bounds.bottom() + minimum_size_.height() -
saved_bounds.height());
}
}
// Widget's SetBounds method does not further modify the bounds that are
// passed to it.
SetBounds(saved_bounds);
} else {
if (bounds.IsEmpty()) {
// No initial bounds supplied, so size the window to its content and
// center over its parent.
native_window_->AsNativeWidget()->CenterWindow(
non_client_view()->GetPreferredSize());
} else {
// Use the supplied initial bounds.
SetBoundsConstrained(bounds, NULL);
}
}
}
} // namespace views } // namespace views
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "views/window/native_window_delegate.h" #include "views/window/native_window_delegate.h"
namespace gfx { namespace gfx {
class Font;
class Rect; class Rect;
class Size; class Size;
} // namespace gfx } // namespace gfx
...@@ -50,22 +49,11 @@ class Window : public Widget, ...@@ -50,22 +49,11 @@ class Window : public Widget,
const gfx::Rect& bounds, const gfx::Rect& bounds,
WindowDelegate* window_delegate); WindowDelegate* window_delegate);
// Returns the preferred size of the contents view of this window based on
// its localized size data. The width in cols is held in a localized string
// resource identified by |col_resource_id|, the height in the same fashion.
// TODO(beng): This should eventually live somewhere else, probably closer to
// ClientView.
static int GetLocalizedContentsWidth(int col_resource_id);
static int GetLocalizedContentsHeight(int row_resource_id);
static gfx::Size GetLocalizedContentsSize(int col_resource_id,
int row_resource_id);
// Initializes the window. Must be called before any post-configuration // Initializes the window. Must be called before any post-configuration
// operations are performed. // operations are performed.
void InitWindow(const InitParams& params); void InitWindow(const InitParams& params);
// Overridden from Widget: // Overridden from Widget:
virtual void Show() OVERRIDE;
virtual Window* AsWindow() OVERRIDE; virtual Window* AsWindow() OVERRIDE;
virtual const Window* AsWindow() const OVERRIDE; virtual const Window* AsWindow() const OVERRIDE;
...@@ -81,24 +69,11 @@ class Window : public Widget, ...@@ -81,24 +69,11 @@ class Window : public Widget,
protected: protected:
// Overridden from NativeWindowDelegate: // Overridden from NativeWindowDelegate:
virtual bool IsModal() const OVERRIDE;
virtual bool IsDialogBox() const OVERRIDE;
virtual void OnNativeWindowCreated(const gfx::Rect& bounds) OVERRIDE;
virtual internal::NativeWidgetDelegate* AsNativeWidgetDelegate() OVERRIDE; virtual internal::NativeWidgetDelegate* AsNativeWidgetDelegate() OVERRIDE;
private: private:
// Sizes and positions the window just after it is created.
void SetInitialBounds(const gfx::Rect& bounds);
NativeWindow* native_window_; NativeWindow* native_window_;
// The saved maximized state for this window. See note in SetInitialBounds
// that explains why we save this.
bool saved_maximized_state_;
// The smallest size the window can be.
gfx::Size minimum_size_;
DISALLOW_COPY_AND_ASSIGN(Window); DISALLOW_COPY_AND_ASSIGN(Window);
}; };
......
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