This source file includes following definitions.
- BuildRootLayers
- CreateNativeWidget
- can_activate_
- DeleteDelegate
- GetWidget
- GetWidget
- CanActivate
- ShouldAdvanceFocusToTopLevelWidget
- force_show_in_taskbar
- force_show_in_taskbar
- movement_disabled_
- CreateWindow
- CreateWindowWithBounds
- CreateWindowWithParent
- CreateWindowWithParentAndBounds
- CreateWindowWithContext
- CreateWindowWithContextAndBounds
- CreateWindowAsFramelessChild
- GetWidgetForNativeView
- GetWidgetForNativeWindow
- GetTopLevelWidgetForNativeView
- GetAllChildWidgets
- GetAllOwnedWidgets
- ReparentNativeView
- GetLocalizedContentsWidth
- GetLocalizedContentsHeight
- GetLocalizedContentsSize
- RequiresNonClientView
- Init
- GetNativeView
- GetNativeWindow
- AddObserver
- RemoveObserver
- HasObserver
- GetAccelerator
- ViewHierarchyChanged
- NotifyNativeViewHierarchyWillChange
- NotifyNativeViewHierarchyChanged
- GetTopLevelWidget
- GetTopLevelWidget
- SetContentsView
- GetContentsView
- GetWindowBoundsInScreen
- GetClientAreaBoundsInScreen
- GetRestoredBounds
- SetBounds
- SetSize
- CenterWindow
- SetBoundsConstrained
- SetVisibilityChangedAnimationsEnabled
- RunMoveLoop
- EndMoveLoop
- StackAboveWidget
- StackAbove
- StackAtTop
- StackBelow
- SetShape
- Close
- CloseNow
- IsClosed
- Show
- Hide
- ShowInactive
- Activate
- Deactivate
- IsActive
- DisableInactiveRendering
- SetAlwaysOnTop
- IsAlwaysOnTop
- SetVisibleOnAllWorkspaces
- Maximize
- Minimize
- Restore
- IsMaximized
- IsMinimized
- SetFullscreen
- IsFullscreen
- SetOpacity
- SetUseDragFrame
- FlashFrame
- GetRootView
- GetRootView
- IsVisible
- GetThemeProvider
- GetNativeTheme
- GetFocusManager
- GetFocusManager
- GetInputMethod
- GetInputMethod
- RunShellDrag
- SchedulePaintInRect
- SetCursor
- IsMouseEventsEnabled
- SetNativeWindowProperty
- GetNativeWindowProperty
- UpdateWindowTitle
- UpdateWindowIcon
- GetFocusTraversable
- ThemeChanged
- LocaleChanged
- SetFocusTraversableParent
- SetFocusTraversableParentView
- ClearNativeFocus
- CreateNonClientFrameView
- ShouldUseNativeFrame
- ShouldWindowContentsBeTransparent
- DebugToggleFrameType
- FrameTypeChanged
- GetCompositor
- GetCompositor
- GetLayer
- ReorderNativeViews
- UpdateRootLayers
- native_widget
- native_widget
- SetCapture
- ReleaseCapture
- HasCapture
- GetTooltipManager
- GetTooltipManager
- GetWorkAreaBoundsInScreen
- SynthesizeMouseMoveEvent
- OnRootViewLayout
- OnOwnerClosing
- IsModal
- IsDialogBox
- CanActivate
- IsInactiveRenderingDisabled
- EnableInactiveRendering
- OnNativeWidgetActivationChanged
- OnNativeFocus
- OnNativeBlur
- OnNativeWidgetVisibilityChanging
- OnNativeWidgetVisibilityChanged
- OnNativeWidgetCreated
- OnNativeWidgetDestroying
- OnNativeWidgetDestroyed
- GetMinimumSize
- GetMaximumSize
- OnNativeWidgetMove
- OnNativeWidgetSizeChanged
- OnNativeWidgetBeginUserBoundsChange
- OnNativeWidgetEndUserBoundsChange
- HasFocusManager
- OnNativeWidgetPaintAccelerated
- OnNativeWidgetPaint
- GetNonClientComponent
- OnKeyEvent
- OnMouseEvent
- OnMouseCaptureLost
- OnScrollEvent
- OnGestureEvent
- ExecuteCommand
- GetInputMethodDirect
- GetRootLayers
- HasHitTestMask
- GetHitTestMask
- AsWidget
- AsWidget
- SetInitialFocus
- GetEventProcessor
- GetFocusSearch
- GetFocusTraversableParent
- GetFocusTraversableParentView
- CreateRootView
- DestroyRootView
- SetInactiveRenderingDisabled
- SaveWindowPlacement
- SetInitialBounds
- SetInitialBoundsForFramelessWindow
- GetSavedWindowPlacement
- CreateInputMethod
- ReplaceInputMethod
- AsNativeWidgetPrivate
#include "ui/views/widget/widget.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/default_theme_provider.h"
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/events/event.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/focus/focus_manager_factory.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/focus/widget_focus_manager.h"
#include "ui/views/ime/input_method.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_deletion_observer.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/custom_frame_view.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
namespace {
void BuildRootLayers(View* view, std::vector<ui::Layer*>* layers) {
if (view->layer()) {
layers->push_back(view->layer());
} else {
for (int i = 0; i < view->child_count(); ++i)
BuildRootLayers(view->child_at(i), layers);
}
}
NativeWidget* CreateNativeWidget(NativeWidget* native_widget,
internal::NativeWidgetDelegate* delegate) {
if (!native_widget) {
native_widget =
internal::NativeWidgetPrivate::CreateNativeWidget(delegate);
}
return native_widget;
}
}
class DefaultWidgetDelegate : public WidgetDelegate {
public:
DefaultWidgetDelegate(Widget* widget, const Widget::InitParams& params)
: widget_(widget),
can_activate_(!params.child &&
params.type != Widget::InitParams::TYPE_POPUP &&
params.type != Widget::InitParams::TYPE_DRAG) {
}
virtual ~DefaultWidgetDelegate() {}
virtual void DeleteDelegate() OVERRIDE {
delete this;
}
virtual Widget* GetWidget() OVERRIDE {
return widget_;
}
virtual const Widget* GetWidget() const OVERRIDE {
return widget_;
}
virtual bool CanActivate() const OVERRIDE {
return can_activate_;
}
virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE {
return true;
}
private:
Widget* widget_;
bool can_activate_;
DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate);
};
Widget::InitParams::InitParams()
: type(TYPE_WINDOW),
delegate(NULL),
child(false),
opacity(INFER_OPACITY),
accept_events(true),
can_activate(true),
keep_on_top(false),
visible_on_all_workspaces(false),
ownership(NATIVE_WIDGET_OWNS_WIDGET),
mirror_origin_in_rtl(false),
has_dropshadow(false),
remove_standard_frame(false),
use_system_default_icon(false),
show_state(ui::SHOW_STATE_DEFAULT),
double_buffer(false),
parent(NULL),
native_widget(NULL),
desktop_window_tree_host(NULL),
top_level(false),
layer_type(aura::WINDOW_LAYER_TEXTURED),
context(NULL),
force_show_in_taskbar(false) {
}
Widget::InitParams::InitParams(Type type)
: type(type),
delegate(NULL),
child(type == TYPE_CONTROL),
opacity(INFER_OPACITY),
accept_events(true),
can_activate(type != TYPE_POPUP && type != TYPE_MENU &&
type != TYPE_DRAG),
keep_on_top(type == TYPE_MENU || type == TYPE_DRAG),
visible_on_all_workspaces(false),
ownership(NATIVE_WIDGET_OWNS_WIDGET),
mirror_origin_in_rtl(false),
has_dropshadow(false),
remove_standard_frame(false),
use_system_default_icon(false),
show_state(ui::SHOW_STATE_DEFAULT),
double_buffer(false),
parent(NULL),
native_widget(NULL),
desktop_window_tree_host(NULL),
top_level(false),
layer_type(aura::WINDOW_LAYER_TEXTURED),
context(NULL),
force_show_in_taskbar(false) {
}
Widget::InitParams::~InitParams() {
}
Widget::Widget()
: native_widget_(NULL),
widget_delegate_(NULL),
non_client_view_(NULL),
dragged_view_(NULL),
ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
is_secondary_widget_(true),
frame_type_(FRAME_TYPE_DEFAULT),
disable_inactive_rendering_(false),
widget_closed_(false),
saved_show_state_(ui::SHOW_STATE_DEFAULT),
focus_on_creation_(true),
is_top_level_(false),
native_widget_initialized_(false),
native_widget_destroyed_(false),
is_mouse_button_pressed_(false),
is_touch_down_(false),
last_mouse_event_was_move_(false),
auto_release_capture_(true),
root_layers_dirty_(false),
movement_disabled_(false) {
}
Widget::~Widget() {
DestroyRootView();
if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) {
delete native_widget_;
} else {
DCHECK(native_widget_destroyed_)
<< "Destroying a widget with a live native widget. "
<< "Widget probably should use WIDGET_OWNS_NATIVE_WIDGET ownership.";
}
}
Widget* Widget::CreateWindow(WidgetDelegate* delegate) {
return CreateWindowWithBounds(delegate, gfx::Rect());
}
Widget* Widget::CreateWindowWithBounds(WidgetDelegate* delegate,
const gfx::Rect& bounds) {
Widget* widget = new Widget;
Widget::InitParams params;
params.bounds = bounds;
params.delegate = delegate;
params.top_level = true;
widget->Init(params);
return widget;
}
Widget* Widget::CreateWindowWithParent(WidgetDelegate* delegate,
gfx::NativeWindow parent) {
return CreateWindowWithParentAndBounds(delegate, parent, gfx::Rect());
}
Widget* Widget::CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
gfx::NativeWindow parent,
const gfx::Rect& bounds) {
Widget* widget = new Widget;
Widget::InitParams params;
params.delegate = delegate;
params.parent = parent;
params.bounds = bounds;
widget->Init(params);
return widget;
}
Widget* Widget::CreateWindowWithContext(WidgetDelegate* delegate,
gfx::NativeView context) {
return CreateWindowWithContextAndBounds(delegate, context, gfx::Rect());
}
Widget* Widget::CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
gfx::NativeView context,
const gfx::Rect& bounds) {
Widget* widget = new Widget;
Widget::InitParams params;
params.delegate = delegate;
params.context = context;
params.bounds = bounds;
widget->Init(params);
return widget;
}
Widget* Widget::CreateWindowAsFramelessChild(WidgetDelegate* widget_delegate,
gfx::NativeView parent) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params;
params.delegate = widget_delegate;
params.child = true;
params.parent = parent;
params.remove_standard_frame = true;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
widget->Init(params);
return widget;
}
Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {
internal::NativeWidgetPrivate* native_widget =
internal::NativeWidgetPrivate::GetNativeWidgetForNativeView(native_view);
return native_widget ? native_widget->GetWidget() : NULL;
}
Widget* Widget::GetWidgetForNativeWindow(gfx::NativeWindow native_window) {
internal::NativeWidgetPrivate* native_widget =
internal::NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
native_window);
return native_widget ? native_widget->GetWidget() : NULL;
}
Widget* Widget::GetTopLevelWidgetForNativeView(gfx::NativeView native_view) {
internal::NativeWidgetPrivate* native_widget =
internal::NativeWidgetPrivate::GetTopLevelNativeWidget(native_view);
return native_widget ? native_widget->GetWidget() : NULL;
}
void Widget::GetAllChildWidgets(gfx::NativeView native_view,
Widgets* children) {
internal::NativeWidgetPrivate::GetAllChildWidgets(native_view, children);
}
void Widget::GetAllOwnedWidgets(gfx::NativeView native_view,
Widgets* owned) {
internal::NativeWidgetPrivate::GetAllOwnedWidgets(native_view, owned);
}
void Widget::ReparentNativeView(gfx::NativeView native_view,
gfx::NativeView new_parent) {
internal::NativeWidgetPrivate::ReparentNativeView(native_view, new_parent);
}
int Widget::GetLocalizedContentsWidth(int col_resource_id) {
return ui::GetLocalizedContentsWidthForFont(col_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
}
int Widget::GetLocalizedContentsHeight(int row_resource_id) {
return ui::GetLocalizedContentsHeightForFont(row_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
}
gfx::Size Widget::GetLocalizedContentsSize(int col_resource_id,
int row_resource_id) {
return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
GetLocalizedContentsHeight(row_resource_id));
}
bool Widget::RequiresNonClientView(InitParams::Type type) {
return type == InitParams::TYPE_WINDOW ||
type == InitParams::TYPE_PANEL ||
type == InitParams::TYPE_BUBBLE;
}
void Widget::Init(const InitParams& in_params) {
TRACE_EVENT0("views", "Widget::Init");
InitParams params = in_params;
is_top_level_ = params.top_level ||
(!params.child &&
params.type != InitParams::TYPE_CONTROL &&
params.type != InitParams::TYPE_TOOLTIP);
params.top_level = is_top_level_;
if (params.opacity == views::Widget::InitParams::INFER_OPACITY &&
params.type != views::Widget::InitParams::TYPE_WINDOW &&
params.type != views::Widget::InitParams::TYPE_PANEL)
params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
if (ViewsDelegate::views_delegate)
ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this);
if (params.opacity == views::Widget::InitParams::INFER_OPACITY)
params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
widget_delegate_ = params.delegate ?
params.delegate : new DefaultWidgetDelegate(this, params);
ownership_ = params.ownership;
native_widget_ = CreateNativeWidget(params.native_widget, this)->
AsNativeWidgetPrivate();
root_view_.reset(CreateRootView());
default_theme_provider_.reset(new ui::DefaultThemeProvider);
if (params.type == InitParams::TYPE_MENU) {
is_mouse_button_pressed_ =
internal::NativeWidgetPrivate::IsMouseButtonDown();
}
native_widget_->InitNativeWidget(params);
if (RequiresNonClientView(params.type)) {
non_client_view_ = new NonClientView;
non_client_view_->SetFrameView(CreateNonClientFrameView());
non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
non_client_view_->SetOverlayView(widget_delegate_->CreateOverlayView());
SetContentsView(non_client_view_);
UpdateWindowTitle();
non_client_view_->ResetWindowControls();
SetInitialBounds(params.bounds);
if (params.show_state == ui::SHOW_STATE_MAXIMIZED)
Maximize();
else if (params.show_state == ui::SHOW_STATE_MINIMIZED)
Minimize();
} else if (params.delegate) {
SetContentsView(params.delegate->GetContentsView());
SetInitialBoundsForFramelessWindow(params.bounds);
}
native_widget_initialized_ = true;
}
gfx::NativeView Widget::GetNativeView() const {
return native_widget_->GetNativeView();
}
gfx::NativeWindow Widget::GetNativeWindow() const {
return native_widget_->GetNativeWindow();
}
void Widget::AddObserver(WidgetObserver* observer) {
observers_.AddObserver(observer);
}
void Widget::RemoveObserver(WidgetObserver* observer) {
observers_.RemoveObserver(observer);
}
bool Widget::HasObserver(WidgetObserver* observer) {
return observers_.HasObserver(observer);
}
bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) {
return false;
}
void Widget::ViewHierarchyChanged(
const View::ViewHierarchyChangedDetails& details) {
if (!details.is_add) {
if (details.child == dragged_view_)
dragged_view_ = NULL;
FocusManager* focus_manager = GetFocusManager();
if (focus_manager)
focus_manager->ViewRemoved(details.child);
ViewStorage::GetInstance()->ViewRemoved(details.child);
native_widget_->ViewRemoved(details.child);
}
}
void Widget::NotifyNativeViewHierarchyWillChange() {
FocusManager* focus_manager = GetFocusManager();
if (focus_manager)
focus_manager->ViewRemoved(root_view_.get());
}
void Widget::NotifyNativeViewHierarchyChanged() {
root_view_->NotifyNativeViewHierarchyChanged();
}
Widget* Widget::GetTopLevelWidget() {
return const_cast<Widget*>(
static_cast<const Widget*>(this)->GetTopLevelWidget());
}
const Widget* Widget::GetTopLevelWidget() const {
return is_top_level() ? this : native_widget_->GetTopLevelWidget();
}
void Widget::SetContentsView(View* view) {
if (view == GetContentsView())
return;
root_view_->SetContentsView(view);
if (non_client_view_ != view) {
DCHECK(!non_client_view_);
non_client_view_ = NULL;
}
}
View* Widget::GetContentsView() {
return root_view_->GetContentsView();
}
gfx::Rect Widget::GetWindowBoundsInScreen() const {
return native_widget_->GetWindowBoundsInScreen();
}
gfx::Rect Widget::GetClientAreaBoundsInScreen() const {
return native_widget_->GetClientAreaBoundsInScreen();
}
gfx::Rect Widget::GetRestoredBounds() const {
return native_widget_->GetRestoredBounds();
}
void Widget::SetBounds(const gfx::Rect& bounds) {
native_widget_->SetBounds(bounds);
}
void Widget::SetSize(const gfx::Size& size) {
native_widget_->SetSize(size);
}
void Widget::CenterWindow(const gfx::Size& size) {
native_widget_->CenterWindow(size);
}
void Widget::SetBoundsConstrained(const gfx::Rect& bounds) {
gfx::Rect work_area =
gfx::Screen::GetScreenFor(GetNativeView())->GetDisplayNearestPoint(
bounds.origin()).work_area();
if (work_area.IsEmpty()) {
SetBounds(bounds);
} else {
work_area.Inset(10, 10, 10, 10);
work_area.AdjustToFit(bounds);
SetBounds(work_area);
}
}
void Widget::SetVisibilityChangedAnimationsEnabled(bool value) {
native_widget_->SetVisibilityChangedAnimationsEnabled(value);
}
Widget::MoveLoopResult Widget::RunMoveLoop(
const gfx::Vector2d& drag_offset,
MoveLoopSource source,
MoveLoopEscapeBehavior escape_behavior) {
return native_widget_->RunMoveLoop(drag_offset, source, escape_behavior);
}
void Widget::EndMoveLoop() {
native_widget_->EndMoveLoop();
}
void Widget::StackAboveWidget(Widget* widget) {
native_widget_->StackAbove(widget->GetNativeView());
}
void Widget::StackAbove(gfx::NativeView native_view) {
native_widget_->StackAbove(native_view);
}
void Widget::StackAtTop() {
native_widget_->StackAtTop();
}
void Widget::StackBelow(gfx::NativeView native_view) {
native_widget_->StackBelow(native_view);
}
void Widget::SetShape(gfx::NativeRegion shape) {
native_widget_->SetShape(shape);
}
void Widget::Close() {
if (widget_closed_) {
return;
}
bool can_close = true;
if (non_client_view_)
can_close = non_client_view_->CanClose();
if (can_close) {
SaveWindowPlacement();
if (is_top_level() && focus_manager_.get())
focus_manager_->SetFocusedView(NULL);
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this));
native_widget_->Close();
widget_closed_ = true;
}
}
void Widget::CloseNow() {
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this));
native_widget_->CloseNow();
}
bool Widget::IsClosed() const {
return widget_closed_;
}
void Widget::Show() {
TRACE_EVENT0("views", "Widget::Show");
if (non_client_view_) {
if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED &&
!initial_restored_bounds_.IsEmpty() &&
!IsFullscreen()) {
native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_);
} else {
native_widget_->ShowWithWindowState(
IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN : saved_show_state_);
}
saved_show_state_ = ui::SHOW_STATE_NORMAL;
} else {
CanActivate()
? native_widget_->Show()
: native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
}
}
void Widget::Hide() {
native_widget_->Hide();
}
void Widget::ShowInactive() {
if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED &&
!initial_restored_bounds_.IsEmpty()) {
SetBounds(initial_restored_bounds_);
saved_show_state_ = ui::SHOW_STATE_NORMAL;
}
native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
}
void Widget::Activate() {
native_widget_->Activate();
}
void Widget::Deactivate() {
native_widget_->Deactivate();
}
bool Widget::IsActive() const {
return native_widget_->IsActive();
}
void Widget::DisableInactiveRendering() {
SetInactiveRenderingDisabled(true);
}
void Widget::SetAlwaysOnTop(bool on_top) {
native_widget_->SetAlwaysOnTop(on_top);
}
bool Widget::IsAlwaysOnTop() const {
return native_widget_->IsAlwaysOnTop();
}
void Widget::SetVisibleOnAllWorkspaces(bool always_visible) {
native_widget_->SetVisibleOnAllWorkspaces(always_visible);
}
void Widget::Maximize() {
native_widget_->Maximize();
}
void Widget::Minimize() {
native_widget_->Minimize();
}
void Widget::Restore() {
native_widget_->Restore();
}
bool Widget::IsMaximized() const {
return native_widget_->IsMaximized();
}
bool Widget::IsMinimized() const {
return native_widget_->IsMinimized();
}
void Widget::SetFullscreen(bool fullscreen) {
if (IsFullscreen() == fullscreen)
return;
native_widget_->SetFullscreen(fullscreen);
if (non_client_view_)
non_client_view_->Layout();
}
bool Widget::IsFullscreen() const {
return native_widget_->IsFullscreen();
}
void Widget::SetOpacity(unsigned char opacity) {
native_widget_->SetOpacity(opacity);
}
void Widget::SetUseDragFrame(bool use_drag_frame) {
native_widget_->SetUseDragFrame(use_drag_frame);
}
void Widget::FlashFrame(bool flash) {
native_widget_->FlashFrame(flash);
}
View* Widget::GetRootView() {
return root_view_.get();
}
const View* Widget::GetRootView() const {
return root_view_.get();
}
bool Widget::IsVisible() const {
return native_widget_->IsVisible();
}
ui::ThemeProvider* Widget::GetThemeProvider() const {
const Widget* root_widget = GetTopLevelWidget();
if (root_widget && root_widget != this) {
ui::ThemeProvider* provider = root_widget->GetThemeProvider();
if (provider)
return provider;
provider = root_widget->default_theme_provider_.get();
if (provider)
return provider;
}
return default_theme_provider_.get();
}
const ui::NativeTheme* Widget::GetNativeTheme() const {
return native_widget_->GetNativeTheme();
}
FocusManager* Widget::GetFocusManager() {
Widget* toplevel_widget = GetTopLevelWidget();
return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
}
const FocusManager* Widget::GetFocusManager() const {
const Widget* toplevel_widget = GetTopLevelWidget();
return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
}
InputMethod* Widget::GetInputMethod() {
return const_cast<InputMethod*>(
const_cast<const Widget*>(this)->GetInputMethod());
}
const InputMethod* Widget::GetInputMethod() const {
if (is_top_level()) {
if (!input_method_.get())
input_method_ = const_cast<Widget*>(this)->CreateInputMethod().Pass();
return input_method_.get();
} else {
const Widget* toplevel = GetTopLevelWidget();
return (toplevel && toplevel != this) ? toplevel->GetInputMethod() : NULL;
}
}
void Widget::RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation,
ui::DragDropTypes::DragEventSource source) {
dragged_view_ = view;
native_widget_->RunShellDrag(view, data, location, operation, source);
if (view && dragged_view_ == view) {
dragged_view_ = NULL;
view->OnDragDone();
}
}
void Widget::SchedulePaintInRect(const gfx::Rect& rect) {
native_widget_->SchedulePaintInRect(rect);
}
void Widget::SetCursor(gfx::NativeCursor cursor) {
native_widget_->SetCursor(cursor);
}
bool Widget::IsMouseEventsEnabled() const {
return native_widget_->IsMouseEventsEnabled();
}
void Widget::SetNativeWindowProperty(const char* name, void* value) {
native_widget_->SetNativeWindowProperty(name, value);
}
void* Widget::GetNativeWindowProperty(const char* name) const {
return native_widget_->GetNativeWindowProperty(name);
}
void Widget::UpdateWindowTitle() {
if (!non_client_view_)
return;
base::string16 window_title = widget_delegate_->GetWindowTitle();
base::i18n::AdjustStringForLocaleDirection(&window_title);
if (!native_widget_->SetWindowTitle(window_title))
return;
non_client_view_->UpdateWindowTitle();
non_client_view_->Layout();
}
void Widget::UpdateWindowIcon() {
if (non_client_view_)
non_client_view_->UpdateWindowIcon();
native_widget_->SetWindowIcons(widget_delegate_->GetWindowIcon(),
widget_delegate_->GetWindowAppIcon());
}
FocusTraversable* Widget::GetFocusTraversable() {
return static_cast<internal::RootView*>(root_view_.get());
}
void Widget::ThemeChanged() {
root_view_->ThemeChanged();
}
void Widget::LocaleChanged() {
root_view_->LocaleChanged();
}
void Widget::SetFocusTraversableParent(FocusTraversable* parent) {
root_view_->SetFocusTraversableParent(parent);
}
void Widget::SetFocusTraversableParentView(View* parent_view) {
root_view_->SetFocusTraversableParentView(parent_view);
}
void Widget::ClearNativeFocus() {
native_widget_->ClearNativeFocus();
}
NonClientFrameView* Widget::CreateNonClientFrameView() {
NonClientFrameView* frame_view =
widget_delegate_->CreateNonClientFrameView(this);
if (!frame_view)
frame_view = native_widget_->CreateNonClientFrameView();
if (!frame_view && ViewsDelegate::views_delegate) {
frame_view =
ViewsDelegate::views_delegate->CreateDefaultNonClientFrameView(this);
}
if (frame_view)
return frame_view;
CustomFrameView* custom_frame_view = new CustomFrameView;
custom_frame_view->Init(this);
return custom_frame_view;
}
bool Widget::ShouldUseNativeFrame() const {
if (frame_type_ != FRAME_TYPE_DEFAULT)
return frame_type_ == FRAME_TYPE_FORCE_NATIVE;
return native_widget_->ShouldUseNativeFrame();
}
bool Widget::ShouldWindowContentsBeTransparent() const {
return native_widget_->ShouldWindowContentsBeTransparent();
}
void Widget::DebugToggleFrameType() {
if (frame_type_ == FRAME_TYPE_DEFAULT) {
frame_type_ = ShouldUseNativeFrame() ? FRAME_TYPE_FORCE_CUSTOM :
FRAME_TYPE_FORCE_NATIVE;
} else {
frame_type_ = frame_type_ == FRAME_TYPE_FORCE_CUSTOM ?
FRAME_TYPE_FORCE_NATIVE : FRAME_TYPE_FORCE_CUSTOM;
}
FrameTypeChanged();
}
void Widget::FrameTypeChanged() {
native_widget_->FrameTypeChanged();
}
const ui::Compositor* Widget::GetCompositor() const {
return native_widget_->GetCompositor();
}
ui::Compositor* Widget::GetCompositor() {
return native_widget_->GetCompositor();
}
ui::Layer* Widget::GetLayer() {
return native_widget_->GetLayer();
}
void Widget::ReorderNativeViews() {
native_widget_->ReorderNativeViews();
}
void Widget::UpdateRootLayers() {
root_layers_dirty_ = true;
}
const NativeWidget* Widget::native_widget() const {
return native_widget_;
}
NativeWidget* Widget::native_widget() {
return native_widget_;
}
void Widget::SetCapture(View* view) {
if (internal::NativeWidgetPrivate::IsMouseButtonDown())
is_mouse_button_pressed_ = true;
if (internal::NativeWidgetPrivate::IsTouchDown())
is_touch_down_ = true;
root_view_->SetMouseHandler(view);
if (!native_widget_->HasCapture())
native_widget_->SetCapture();
}
void Widget::ReleaseCapture() {
if (native_widget_->HasCapture())
native_widget_->ReleaseCapture();
}
bool Widget::HasCapture() {
return native_widget_->HasCapture();
}
TooltipManager* Widget::GetTooltipManager() {
return native_widget_->GetTooltipManager();
}
const TooltipManager* Widget::GetTooltipManager() const {
return native_widget_->GetTooltipManager();
}
gfx::Rect Widget::GetWorkAreaBoundsInScreen() const {
return native_widget_->GetWorkAreaBoundsInScreen();
}
void Widget::SynthesizeMouseMoveEvent() {
last_mouse_event_was_move_ = false;
ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED,
last_mouse_event_position_,
last_mouse_event_position_,
ui::EF_IS_SYNTHESIZED, 0);
root_view_->OnMouseMoved(mouse_event);
}
void Widget::OnRootViewLayout() {
native_widget_->OnRootViewLayout();
}
void Widget::OnOwnerClosing() {
}
bool Widget::IsModal() const {
return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE;
}
bool Widget::IsDialogBox() const {
return !!widget_delegate_->AsDialogDelegate();
}
bool Widget::CanActivate() const {
return widget_delegate_->CanActivate();
}
bool Widget::IsInactiveRenderingDisabled() const {
return disable_inactive_rendering_;
}
void Widget::EnableInactiveRendering() {
SetInactiveRenderingDisabled(false);
}
void Widget::OnNativeWidgetActivationChanged(bool active) {
if (!active && native_widget_initialized_)
SaveWindowPlacement();
FOR_EACH_OBSERVER(WidgetObserver, observers_,
OnWidgetActivationChanged(this, active));
if (IsVisible() && non_client_view())
non_client_view()->frame_view()->SchedulePaint();
}
void Widget::OnNativeFocus(gfx::NativeView old_focused_view) {
WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(old_focused_view,
GetNativeView());
}
void Widget::OnNativeBlur(gfx::NativeView new_focused_view) {
WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(GetNativeView(),
new_focused_view);
}
void Widget::OnNativeWidgetVisibilityChanging(bool visible) {
FOR_EACH_OBSERVER(WidgetObserver, observers_,
OnWidgetVisibilityChanging(this, visible));
}
void Widget::OnNativeWidgetVisibilityChanged(bool visible) {
View* root = GetRootView();
if (root)
root->PropagateVisibilityNotifications(root, visible);
FOR_EACH_OBSERVER(WidgetObserver, observers_,
OnWidgetVisibilityChanged(this, visible));
if (GetCompositor() && root && root->layer())
root->layer()->SetVisible(visible);
}
void Widget::OnNativeWidgetCreated(bool desktop_widget) {
if (is_top_level())
focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget));
native_widget_->InitModalType(widget_delegate_->GetModalType());
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetCreated(this));
}
void Widget::OnNativeWidgetDestroying() {
if (GetFocusManager())
GetFocusManager()->ViewRemoved(root_view_.get());
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroying(this));
if (non_client_view_)
non_client_view_->WindowClosing();
widget_delegate_->WindowClosing();
}
void Widget::OnNativeWidgetDestroyed() {
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroyed(this));
widget_delegate_->DeleteDelegate();
widget_delegate_ = NULL;
native_widget_destroyed_ = true;
}
gfx::Size Widget::GetMinimumSize() {
return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
}
gfx::Size Widget::GetMaximumSize() {
return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
}
void Widget::OnNativeWidgetMove() {
widget_delegate_->OnWidgetMove();
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
this,
GetWindowBoundsInScreen()));
}
void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
root_view_->SetSize(new_size);
if (native_widget_initialized_)
SaveWindowPlacement();
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
this,
GetWindowBoundsInScreen()));
}
void Widget::OnNativeWidgetBeginUserBoundsChange() {
widget_delegate_->OnWindowBeginUserBoundsChange();
}
void Widget::OnNativeWidgetEndUserBoundsChange() {
widget_delegate_->OnWindowEndUserBoundsChange();
}
bool Widget::HasFocusManager() const {
return !!focus_manager_.get();
}
bool Widget::OnNativeWidgetPaintAccelerated(const gfx::Rect& dirty_region) {
ui::Compositor* compositor = GetCompositor();
if (!compositor)
return false;
compositor->ScheduleRedrawRect(dirty_region);
return true;
}
void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) {
if (native_widget_initialized_)
GetRootView()->Paint(canvas);
}
int Widget::GetNonClientComponent(const gfx::Point& point) {
int component = non_client_view_ ?
non_client_view_->NonClientHitTest(point) :
HTNOWHERE;
if (movement_disabled_ && (component == HTCAPTION || component == HTSYSMENU))
return HTNOWHERE;
return component;
}
void Widget::OnKeyEvent(ui::KeyEvent* event) {
SendEventToProcessor(event);
}
void Widget::OnMouseEvent(ui::MouseEvent* event) {
View* root_view = GetRootView();
switch (event->type()) {
case ui::ET_MOUSE_PRESSED: {
last_mouse_event_was_move_ = false;
WidgetDeletionObserver widget_deletion_observer(this);
if (root_view && root_view->OnMousePressed(*event) &&
widget_deletion_observer.IsWidgetAlive() && IsVisible() &&
internal::NativeWidgetPrivate::IsMouseButtonDown()) {
is_mouse_button_pressed_ = true;
if (!native_widget_->HasCapture())
native_widget_->SetCapture();
event->SetHandled();
}
return;
}
case ui::ET_MOUSE_RELEASED:
last_mouse_event_was_move_ = false;
is_mouse_button_pressed_ = false;
if (auto_release_capture_ && native_widget_->HasCapture())
native_widget_->ReleaseCapture();
if (root_view)
root_view->OnMouseReleased(*event);
if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0)
event->SetHandled();
return;
case ui::ET_MOUSE_MOVED:
case ui::ET_MOUSE_DRAGGED:
if (native_widget_->HasCapture() && is_mouse_button_pressed_) {
last_mouse_event_was_move_ = false;
if (root_view)
root_view->OnMouseDragged(*event);
} else if (!last_mouse_event_was_move_ ||
last_mouse_event_position_ != event->location()) {
last_mouse_event_position_ = event->location();
last_mouse_event_was_move_ = true;
if (root_view)
root_view->OnMouseMoved(*event);
}
return;
case ui::ET_MOUSE_EXITED:
last_mouse_event_was_move_ = false;
if (root_view)
root_view->OnMouseExited(*event);
return;
case ui::ET_MOUSEWHEEL:
if (root_view && root_view->OnMouseWheel(
static_cast<const ui::MouseWheelEvent&>(*event)))
event->SetHandled();
return;
default:
return;
}
}
void Widget::OnMouseCaptureLost() {
if (is_mouse_button_pressed_ || is_touch_down_) {
View* root_view = GetRootView();
if (root_view)
root_view->OnMouseCaptureLost();
}
is_touch_down_ = false;
is_mouse_button_pressed_ = false;
}
void Widget::OnScrollEvent(ui::ScrollEvent* event) {
SendEventToProcessor(event);
}
void Widget::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) {
case ui::ET_GESTURE_TAP_DOWN:
is_touch_down_ = true;
break;
case ui::ET_GESTURE_END:
if (event->details().touch_points() == 1)
is_touch_down_ = false;
break;
default:
break;
}
SendEventToProcessor(event);
}
bool Widget::ExecuteCommand(int command_id) {
return widget_delegate_->ExecuteWindowsCommand(command_id);
}
InputMethod* Widget::GetInputMethodDirect() {
return input_method_.get();
}
const std::vector<ui::Layer*>& Widget::GetRootLayers() {
if (root_layers_dirty_) {
root_layers_dirty_ = false;
root_layers_.clear();
BuildRootLayers(GetRootView(), &root_layers_);
}
return root_layers_;
}
bool Widget::HasHitTestMask() const {
return widget_delegate_->WidgetHasHitTestMask();
}
void Widget::GetHitTestMask(gfx::Path* mask) const {
DCHECK(mask);
widget_delegate_->GetWidgetHitTestMask(mask);
}
Widget* Widget::AsWidget() {
return this;
}
const Widget* Widget::AsWidget() const {
return this;
}
bool Widget::SetInitialFocus(ui::WindowShowState show_state) {
View* v = widget_delegate_->GetInitiallyFocusedView();
if (!focus_on_creation_ || show_state == ui::SHOW_STATE_INACTIVE ||
show_state == ui::SHOW_STATE_MINIMIZED) {
if (v)
focus_manager_->SetStoredFocusView(v);
return true;
}
if (v)
v->RequestFocus();
return !!v;
}
ui::EventProcessor* Widget::GetEventProcessor() {
return root_view_.get();
}
FocusSearch* Widget::GetFocusSearch() {
return root_view_->GetFocusSearch();
}
FocusTraversable* Widget::GetFocusTraversableParent() {
NOTREACHED();
return NULL;
}
View* Widget::GetFocusTraversableParentView() {
NOTREACHED();
return NULL;
}
internal::RootView* Widget::CreateRootView() {
return new internal::RootView(this);
}
void Widget::DestroyRootView() {
non_client_view_ = NULL;
root_view_.reset();
input_method_.reset();
}
void Widget::SetInactiveRenderingDisabled(bool value) {
if (value == disable_inactive_rendering_)
return;
disable_inactive_rendering_ = value;
if (non_client_view_)
non_client_view_->SetInactiveRenderingDisabled(value);
}
void Widget::SaveWindowPlacement() {
if (!widget_delegate_)
return;
ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
gfx::Rect bounds;
native_widget_->GetWindowPlacement(&bounds, &show_state);
widget_delegate_->SaveWindowPlacement(bounds, show_state);
}
void Widget::SetInitialBounds(const gfx::Rect& bounds) {
if (!non_client_view_)
return;
gfx::Rect saved_bounds;
if (GetSavedWindowPlacement(&saved_bounds, &saved_show_state_)) {
if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) {
initial_restored_bounds_ = saved_bounds;
} else if (!saved_bounds.IsEmpty()) {
SetBounds(saved_bounds);
}
} else {
if (bounds.IsEmpty()) {
native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
} else {
SetBoundsConstrained(bounds);
}
}
}
void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) {
if (bounds.IsEmpty()) {
View* contents_view = GetContentsView();
DCHECK(contents_view);
gfx::Size size = contents_view->GetPreferredSize();
if (!size.IsEmpty())
native_widget_->CenterWindow(size);
} else {
SetBoundsConstrained(bounds);
}
}
bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds,
ui::WindowShowState* show_state) {
if (widget_delegate_->GetSavedWindowPlacement(this, bounds, show_state)) {
if (!widget_delegate_->ShouldRestoreWindowSize()) {
bounds->set_size(non_client_view_->GetPreferredSize());
} else {
gfx::Size minimum_size = GetMinimumSize();
if (bounds->width() < minimum_size.width())
bounds->set_width(minimum_size.width());
if (bounds->height() < minimum_size.height())
bounds->set_height(minimum_size.height());
}
return true;
}
return false;
}
scoped_ptr<InputMethod> Widget::CreateInputMethod() {
scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod());
if (input_method.get())
input_method->Init(this);
return input_method.Pass();
}
void Widget::ReplaceInputMethod(InputMethod* input_method) {
input_method_.reset(input_method);
input_method->SetDelegate(native_widget_->GetInputMethodDelegate());
input_method->Init(this);
}
namespace internal {
internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
return this;
}
}
}