diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 20:52:36 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 20:52:36 +0000 |
commit | aca5148cbb5c19f23c20e8421ce4e74d3bbd7a05 (patch) | |
tree | 6b6dfa178f15c227bfe6cc2afb61e033d4b1c414 | |
parent | d1735a7513c5516d2a14eaa8355100e4d7a90cef (diff) | |
download | chromium_src-aca5148cbb5c19f23c20e8421ce4e74d3bbd7a05.zip chromium_src-aca5148cbb5c19f23c20e8421ce4e74d3bbd7a05.tar.gz chromium_src-aca5148cbb5c19f23c20e8421ce4e74d3bbd7a05.tar.bz2 |
Remove src/ui/views.
BUG=101590
R=pkasting@chromium.org
Review URL: http://codereview.chromium.org/8395036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107428 0039d316-1c4b-4281-b951-d872f2087c98
54 files changed, 0 insertions, 5886 deletions
@@ -5,16 +5,9 @@ { 'variables': { 'chromium_code': 1, - 'toolkit_views2': 0, # ui/views/ is an experimental framework on Windows. }, 'target_defaults': { 'conditions': [ - ['OS=="win"', - {'variables': {'toolkit_views2': 1}}, - ], - ['toolkit_views2==0', {'sources/': [ - ['exclude', 'views/'], - ]}], ['touchui==0', {'sources/': [ ['exclude', '_(touch)\\.cc$'], ]}], @@ -589,11 +582,6 @@ }, ], 'conditions': [ - ['toolkit_views2==1', { - 'includes': [ - 'ui_views.gypi', - ], - }], ['inside_chromium_build==1', { 'includes': [ 'ui_unittests.gypi', diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index a550de2..dd829a4 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -83,24 +83,12 @@ 'gfx/skia_util_unittest.cc', 'gfx/test_suite.cc', 'gfx/test_suite.h', - 'views/rendering/border_unittest.cc', - 'views/view_unittest.cc', - 'views/widget/native_widget_win_unittest.cc', - 'views/widget/root_view_unittest.cc', - 'views/widget/widget_test_util.cc', - 'views/widget/widget_test_util.h', - 'views/widget/widget_unittest.cc', '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', ], 'include_dirs': [ '../', ], 'conditions': [ - ['toolkit_views2==1', { - 'dependencies': [ - 'v2', - ], - }], ['OS == "win"', { 'sources': [ 'base/dragdrop/os_exchange_data_win_unittest.cc', diff --git a/ui/ui_views.gypi b/ui/ui_views.gypi deleted file mode 100644 index 915cce8..0000000 --- a/ui/ui_views.gypi +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'targets': [ - { - 'target_name': 'v2', - 'type': 'static_library', - 'dependencies': [ - '../skia/skia.gyp:skia', - '../ui/base/strings/ui_strings.gyp:ui_strings', - 'ui', - ], - 'sources': [ - 'views/events/accelerator.cc', - 'views/events/accelerator.h', - 'views/events/context_menu_controller.h', - 'views/events/drag_controller.h', - 'views/events/event.cc', - 'views/events/event.h', - 'views/events/focus_event.cc', - 'views/events/focus_event.h', - 'views/focus/accelerator_handler.h', - 'views/focus/accelerator_handler_win.cc', - 'views/focus/focus_manager.cc', - 'views/focus/focus_manager.h', - 'views/focus/focus_search.cc', - 'views/focus/focus_search.h', - 'views/layout/fill_layout.cc', - 'views/layout/fill_layout.h', - 'views/layout/layout_manager.cc', - 'views/layout/layout_manager.h', - 'views/rendering/border.cc', - 'views/rendering/border.h', - 'views/view.cc', - 'views/view.h', - 'views/widget/native_widget.h', - 'views/widget/native_widget_listener.h', - 'views/widget/native_widget_views.cc', - 'views/widget/native_widget_views.h', - 'views/widget/native_widget_win.cc', - 'views/widget/native_widget_win.h', - 'views/widget/root_view.cc', - 'views/widget/root_view.h', - 'views/widget/widget.cc', - 'views/widget/widget.h', - 'views/window/window.cc', - 'views/window/window.h', - 'views/window/native_window.h', - 'views/window/native_window_views.cc', - 'views/window/native_window_views.h', - 'views/window/native_window_win.cc', - 'views/window/native_window_win.h', - ], - 'include_dirs': [ - '../', - ], - 'conditions': [ - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '../build/linux/system.gyp:gtk', - '../build/linux/system.gyp:x11', - '../build/linux/system.gyp:xext', - ], - 'sources!': [ - ], - }], - ['OS=="win"', { - 'include_dirs': [ - '../third_party/wtl/include', - ], - }], - ], - }, - { - 'target_name': 'views_demo', - 'type': 'executable', - 'dependencies': [ - '../skia/skia.gyp:skia', - 'v2', - ], - 'sources': [ - 'views/demo/main.cc', - ], - 'include_dirs': [ - '../', - ], - 'conditions': [ - ['OS=="win"', { - 'sources': [ - 'views/widget/widget.rc', - 'views/widget/widget_resource.h', - ], - }], - ], - }, - ], -} diff --git a/ui/views/OWNERS b/ui/views/OWNERS deleted file mode 100644 index 3ff71eb..0000000 --- a/ui/views/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -ben@chromium.org
-sky@chromium.org
diff --git a/ui/views/README.chromium b/ui/views/README.chromium deleted file mode 100644 index 7975925..0000000 --- a/ui/views/README.chromium +++ /dev/null @@ -1,4 +0,0 @@ -This is a work-in-progress Views prototype that is not currently in use.
-
-Please contact beng with questions.
-
diff --git a/ui/views/demo/main.cc b/ui/views/demo/main.cc deleted file mode 100644 index 19dfc9d..0000000 --- a/ui/views/demo/main.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <windows.h> -#include <atlbase.h> -#include <atlapp.h> -#include <atlcrack.h> -#include <atlmisc.h> - -#include "base/at_exit.h" -#include "base/message_loop.h" -#include "ui/gfx/canvas.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/native_widget_win.h" - -class V2DemoDispatcher : public MessageLoopForUI::Dispatcher { - public: - V2DemoDispatcher() {} - virtual ~V2DemoDispatcher() {} - - private: - // Overridden from MessageLoopForUI::Dispatcher: - virtual bool Dispatch(const MSG& msg) { - TranslateMessage(&msg); - DispatchMessage(&msg); - return true; - } - - DISALLOW_COPY_AND_ASSIGN(V2DemoDispatcher); -}; - -class ColorView : public ui::View { - public: - explicit ColorView(SkColor color) : color_(color) { - } - ColorView() : color_(SK_ColorBLACK) {} - virtual ~ColorView() {} - - protected: - SkColor color() const { return color_; } - void set_color(SkColor color) { color_ = color; } - - private: - // Overridden from ui::View: - virtual void OnPaint(gfx::Canvas* canvas) { - canvas->FillRectInt(color_, 0, 0, width(), height()); - } - virtual bool OnMousePressed(const ui::MouseEvent& event) { - color_ = color_ == SK_ColorBLACK ? SK_ColorWHITE : SK_ColorBLACK; - Invalidate(); - return true; - } - virtual void OnMouseReleased(const ui::MouseEvent& event, bool canceled) { - color_ = color_ == SK_ColorWHITE ? SK_ColorMAGENTA : SK_ColorGREEN; - Invalidate(); - } - virtual void OnMouseMoved(const ui::MouseEvent& event) { - U8CPU r = SkColorGetR(color_); - color_ = SkColorSetRGB(++r % 255, SkColorGetG(color_), - SkColorGetB(color_)); - Invalidate(); - } - virtual bool OnMouseDragged(const ui::MouseEvent& event) { - U8CPU g = SkColorGetG(color_); - color_ = SkColorSetRGB(SkColorGetR(color_), ++g % 255, - SkColorGetB(color_)); - Invalidate(); - return true; - } - - SkColor color_; - - DISALLOW_COPY_AND_ASSIGN(ColorView); -}; - -class FancyPantsView : public ColorView { - public: - FancyPantsView() - : ColorView(SK_ColorMAGENTA), - c1_(new ColorView(SK_ColorGREEN)), - c2_(new ColorView(SK_ColorRED)) { - AddChildView(c1_); - AddChildView(c2_); - } - virtual ~FancyPantsView() {} - - // Overridden from ui::View: - virtual void Layout() { - c1_->SetBounds(gfx::Rect(20, 20, std::max(width() - 40, 0), - std::max(height() - 40, 0))); - c2_->SetBounds(gfx::Rect(50, 50, 50, 50)); - Invalidate(); - } - virtual bool OnMousePressed(const ui::MouseEvent& event) { - old_color_ = color(); - set_color(SK_ColorWHITE); - mouse_offset_ = event.location(); - return true; - } - virtual bool OnMouseDragged(const ui::MouseEvent& event) { - gfx::Rect old_bounds = bounds(); - SetOrigin(gfx::Point(event.x() - mouse_offset_.x(), - event.y() - mouse_offset_.y())); - gfx::Rect new_bounds = bounds(); - parent()->InvalidateRect(old_bounds.Union(new_bounds)); - return true; - } - virtual void OnMouseReleased(const ui::MouseEvent& event) { - set_color(old_color_); - } - virtual void OnMouseCaptureLost() { - set_color(SK_ColorYELLOW); - } - - private: - View* c1_; - View* c2_; - - gfx::Point mouse_offset_; - SkColor old_color_; - - DISALLOW_COPY_AND_ASSIGN(FancyPantsView); -}; - - - -class ContentsView : public ColorView { - public: - ContentsView() - : c1_(new ColorView(SK_ColorBLUE)), - c2_(new ColorView(SK_ColorGREEN)), - c3_(new FancyPantsView()), - ColorView(SK_ColorRED) { - set_parent_owned(false); - AddChildView(c1_); - AddChildView(c2_); - c3_->SetOrigin(gfx::Point(200, 200)); - AddChildView(c3_); - } - - virtual ~ContentsView() {} - - void Init() { - //c3_->SetHasLayer(true); - } - - private: - // Overridden from ui::View: - virtual void Layout() { - c1_->SetBounds(gfx::Rect(20, 20, std::max(width() - 40, 0), - std::max(height() - 40, 0))); - c2_->SetBounds(gfx::Rect(50, 50, 50, 50)); - c3_->SetSize(gfx::Size(75, 75)); - Invalidate(); - } - - View* c1_; - View* c2_; - FancyPantsView* c3_; -}; - -int main(int argc, char **argv) { - OleInitialize(NULL); - base::AtExitManager exit_manager; - MessageLoop main_message_loop(MessageLoop::TYPE_UI); - - ContentsView cv; - ui::Widget widget(&cv); - widget.InitWithNativeViewParent(NULL, gfx::Rect(20, 20, 400, 400)); - cv.Init(); - widget.Show(); - - V2DemoDispatcher dispatcher; - MessageLoopForUI::current()->Run(&dispatcher); - - OleUninitialize(); -} diff --git a/ui/views/events/accelerator.cc b/ui/views/events/accelerator.cc deleted file mode 100644 index 8cd7f03a..0000000 --- a/ui/views/events/accelerator.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/events/accelerator.h" - -#if defined(OS_WIN) -#include <windows.h> -#elif defined(TOOLKIT_USES_GTK) -#include <gdk/gdk.h> -#endif - -#include "base/i18n/rtl.h" -#include "base/logging.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "grit/ui_strings.h" -#include "ui/base/l10n/l10n_util.h" - -namespace ui { - -namespace { - -bool IsShiftDown(const Accelerator& accelerator) { - return (accelerator.key_code() & VKEY_SHIFT) == VKEY_SHIFT; -} - -bool IsCtrlDown(const Accelerator& accelerator) { - return (accelerator.key_code() & VKEY_CONTROL) == VKEY_CONTROL; -} - -bool IsAltDown(const Accelerator& accelerator) { - return (accelerator.key_code() & VKEY_MENU) == VKEY_MENU; -} - -} // namespace - -string16 GetShortcutTextForAccelerator(const Accelerator& accelerator) { - int string_id = 0; - switch(accelerator.key_code()) { - case ui::VKEY_TAB: - string_id = IDS_APP_TAB_KEY; - break; - case ui::VKEY_RETURN: - string_id = IDS_APP_ENTER_KEY; - break; - case ui::VKEY_ESCAPE: - string_id = IDS_APP_ESC_KEY; - break; - case ui::VKEY_PRIOR: - string_id = IDS_APP_PAGEUP_KEY; - break; - case ui::VKEY_NEXT: - string_id = IDS_APP_PAGEDOWN_KEY; - break; - case ui::VKEY_END: - string_id = IDS_APP_END_KEY; - break; - case ui::VKEY_HOME: - string_id = IDS_APP_HOME_KEY; - break; - case ui::VKEY_INSERT: - string_id = IDS_APP_INSERT_KEY; - break; - case ui::VKEY_DELETE: - string_id = IDS_APP_DELETE_KEY; - break; - case ui::VKEY_LEFT: - string_id = IDS_APP_LEFT_ARROW_KEY; - break; - case ui::VKEY_RIGHT: - string_id = IDS_APP_RIGHT_ARROW_KEY; - break; - case ui::VKEY_BACK: - string_id = IDS_APP_BACKSPACE_KEY; - break; - case ui::VKEY_F1: - string_id = IDS_APP_F1_KEY; - break; - case ui::VKEY_F11: - string_id = IDS_APP_F11_KEY; - break; - default: - break; - } - - string16 shortcut; - if (!string_id) { -#if defined(OS_WIN) - // Our fallback is to try translate the key code to a regular character - // unless it is one of digits (VK_0 to VK_9). Some keyboard - // layouts have characters other than digits assigned in - // an unshifted mode (e.g. French AZERY layout has 'a with grave - // accent' for '0'). For display in the menu (e.g. Ctrl-0 for the - // default zoom level), we leave VK_[0-9] alone without translation. - wchar_t key; - if (accelerator.key_code() >= '0' && accelerator.key_code() <= '9') - key = accelerator.key_code(); - else - key = LOWORD(::MapVirtualKeyW(accelerator.key_code(), MAPVK_VK_TO_CHAR)); - shortcut += key; -#elif defined(TOOLKIT_USES_GTK) - const gchar* name = NULL; - switch (accelerator.key_code()) { - case ui::VKEY_OEM_2: - name = static_cast<const gchar*>("/"); - break; - default: - name = gdk_keyval_name(gdk_keyval_to_lower(accelerator.key_code())); - break; - } - if (name) { - if (name[0] != 0 && name[1] == 0) - shortcut += static_cast<string16::value_type>(g_ascii_toupper(name[0])); - else - shortcut += UTF8ToUTF16(name); - } -#endif - } else { - shortcut = l10n_util::GetStringUTF16(string_id); - } - - // Checking whether the character used for the accelerator is alphanumeric. - // If it is not, then we need to adjust the string later on if the locale is - // right-to-left. See below for more information of why such adjustment is - // required. - string16 shortcut_rtl; - bool adjust_shortcut_for_rtl = false; - if (base::i18n::IsRTL() && shortcut.length() == 1 && - !IsAsciiAlpha(shortcut.at(0)) && !IsAsciiDigit(shortcut.at(0))) { - adjust_shortcut_for_rtl = true; - shortcut_rtl.assign(shortcut); - } - - if (IsShiftDown(accelerator)) - shortcut = l10n_util::GetStringFUTF16(IDS_APP_SHIFT_MODIFIER, shortcut); - - // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut. - // See http://blogs.msdn.com/oldnewthing/archive/2004/03/29/101121.aspx for - // more information. - if (IsCtrlDown(accelerator)) - shortcut = l10n_util::GetStringFUTF16(IDS_APP_CONTROL_MODIFIER, shortcut); - else if (IsAltDown(accelerator)) - shortcut = l10n_util::GetStringFUTF16(IDS_APP_ALT_MODIFIER, shortcut); - - // For some reason, menus in Windows ignore standard Unicode directionality - // marks (such as LRE, PDF, etc.). On RTL locales, we use RTL menus and - // therefore any text we draw for the menu items is drawn in an RTL context. - // Thus, the text "Ctrl++" (which we currently use for the Zoom In option) - // appears as "++Ctrl" in RTL because the Unicode BiDi algorithm puts - // punctuations on the left when the context is right-to-left. Shortcuts that - // do not end with a punctuation mark (such as "Ctrl+H" do not have this - // problem). - // - // The only way to solve this problem is to adjust the string if the locale - // is RTL so that it is drawn correnctly in an RTL context. Instead of - // returning "Ctrl++" in the above example, we return "++Ctrl". This will - // cause the text to appear as "Ctrl++" when Windows draws the string in an - // RTL context because the punctunation no longer appears at the end of the - // string. - // - // TODO(idana) bug# 1232732: this hack can be avoided if instead of using - // views::Menu we use views::MenuItemView because the latter is a View - // subclass and therefore it supports marking text as RTL or LTR using - // standard Unicode directionality marks. - if (adjust_shortcut_for_rtl) { - int key_length = static_cast<int>(shortcut_rtl.length()); - DCHECK_GT(key_length, 0); - shortcut_rtl.append(ASCIIToUTF16("+")); - - // Subtracting the size of the shortcut key and 1 for the '+' sign. - shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); - shortcut.swap(shortcut_rtl); - } - - return shortcut; -} - -} // namespace ui diff --git a/ui/views/events/accelerator.h b/ui/views/events/accelerator.h deleted file mode 100644 index 965c447..0000000 --- a/ui/views/events/accelerator.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_EVENTS_ACCELERATOR_H_ -#define UI_VIEWS_EVENTS_ACCELERATOR_H_ -#pragma once - -#include "ui/base/models/accelerator.h" - -namespace ui { - -string16 GetShortcutTextForAccelerator(const Accelerator& accelerator); - -// An interface that classes that want to register for keyboard accelerators -// should implement. -class AcceleratorTarget { - public: - // This method should return true if the accelerator was processed. - virtual bool AcceleratorPressed(const Accelerator& accelerator) = 0; - - protected: - virtual ~AcceleratorTarget() {} -}; - -} // namespace ui - -#endif // UI_VIEWS_EVENTS_ACCELERATOR_H_ diff --git a/ui/views/events/context_menu_controller.h b/ui/views/events/context_menu_controller.h deleted file mode 100644 index ab35a32..0000000 --- a/ui/views/events/context_menu_controller.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_EVENTS_CONTEXT_MENU_CONTROLLER_H_ -#define UI_VIEWS_EVENTS_CONTEXT_MENU_CONTROLLER_H_ -#pragma once - -namespace gfx { -class Point; -} - -namespace ui { - -class View; - -// ContextMenuController is responsible for showing the context menu for a -// View. To use a ContextMenuController invoke SetContextMenuController on a -// View. When the appropriate user gesture occurs ShowContextMenu is invoked -// on the ContextMenuController. -// -// Setting a ContextMenuController on a View makes the View process mouse -// events. -// -// It is up to subclasses that do their own mouse processing to invoke -// the appropriate ContextMenuController method, typically by invoking super's -// implementation for mouse processing. -// -class ContextMenuController { - public: - // Invoked to show the context menu for the source view. If |is_mouse_gesture| - // is true, |point| is the location of the mouse. If |is_mouse_gesture| is - // false, this method was not invoked by a mouse gesture and |point| is the - // recommended location to show the menu at. - // - // |point| is in screen coordinates. - virtual void ShowContextMenuForView(View* source, - const gfx::Point& point, - bool is_mouse_gesture) = 0; - - protected: - virtual ~ContextMenuController() {} -}; - -} // namespace ui - -#endif // UI_VIEWS_EVENTS_CONTEXT_MENU_CONTROLLER_H_ diff --git a/ui/views/events/drag_controller.h b/ui/views/events/drag_controller.h deleted file mode 100644 index 6344f83..0000000 --- a/ui/views/events/drag_controller.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_EVENTS_DRAG_CONTROLLER_H_ -#define UI_VIEWS_EVENTS_DRAG_CONTROLLER_H_ -#pragma once - -namespace ui { - -// DragController is responsible for writing drag data for a View, as well as -// supplying the supported drag operations without having to subclass View. -class DragController { - public: - // Writes the data for the drag. - virtual void WriteDragDataForView(View* sender, - const gfx::Point& press_pt, - OSExchangeData* data) = 0; - - // Returns the supported drag operations (see DragDropTypes for possible - // values). A drag is only started if this returns a non-zero value. - virtual int GetDragOperationsForView(View* sender, const gfx::Point& p) = 0; - - // Returns true if a drag operation can be started. - // |press_pt| represents the coordinates where the mouse was initially - // pressed down. |p| is the current mouse coordinates. - virtual bool CanStartDragForView(View* sender, - const gfx::Point& press_pt, - const gfx::Point& p) = 0; - - protected: - virtual ~DragController() {} -}; - -} // namespace ui - -#endif // UI_VIEWS_EVENTS_DRAG_CONTROLLER_H_ diff --git a/ui/views/events/event.cc b/ui/views/events/event.cc deleted file mode 100644 index 544c2ad..0000000 --- a/ui/views/events/event.cc +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/events/event.h" - -#include "ui/views/view.h" - -namespace ui { - -//////////////////////////////////////////////////////////////////////////////// -// Event, protected: - -Event::Event(EventType type, int flags) - : type_(type), - flags_(flags) { -} - -int Event::GetModifiers() const { - int modifiers = 0; - if (IsShiftDown()) - modifiers |= VKEY_SHIFT; - if (IsControlDown()) - modifiers |= VKEY_CONTROL; - if (IsAltDown()) - modifiers |= VKEY_MENU; - if (IsCapsLockDown()) - modifiers |= VKEY_CAPITAL; - return modifiers; -} - -//////////////////////////////////////////////////////////////////////////////// -// LocatedEvent, protected: - -LocatedEvent::LocatedEvent(EventType type, - const gfx::Point& location, - int flags) - : Event(type, flags), - location_(location) { -} - -LocatedEvent::LocatedEvent(const LocatedEvent& other, - View* source, - View* target) - : Event(other.type(), other.flags()) { - location_ = other.location(); - View::ConvertPointToView(*source, *target, &location_); -} - -//////////////////////////////////////////////////////////////////////////////// -// MouseEvent, public: - -MouseEvent::MouseEvent(const ui::NativeEvent& native_event) - : LocatedEvent(ui::EventTypeFromNative(native_event), - ui::EventLocationFromNative(native_event), - ui::EventFlagsFromNative(native_event)) { -} - -MouseEvent::MouseEvent(const MouseEvent& other, View* source, View* target) - : LocatedEvent(other, source, target) { -} - -KeyEvent::KeyEvent(const ui::NativeEvent& native_event) - : Event(ui::EventTypeFromNative(native_event), - ui::EventFlagsFromNative(native_event)), - key_code_(ui::KeyboardCodeFromNative(native_event)) { -} - -MouseWheelEvent::MouseWheelEvent(const ui::NativeEvent& native_event) - : LocatedEvent(ui::EventTypeFromNative(native_event), - ui::EventLocationFromNative(native_event), - ui::EventFlagsFromNative(native_event)), - offset_(ui::GetMouseWheelOffset(native_event)) { -} - -} // namespace ui diff --git a/ui/views/events/event.h b/ui/views/events/event.h deleted file mode 100644 index 002608c..0000000 --- a/ui/views/events/event.h +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_EVENTS_EVENT_H_ -#define UI_VIEWS_EVENTS_EVENT_H_ -#pragma once - -#include "base/basictypes.h" -#include "ui/base/events.h" -#include "ui/base/keycodes/keyboard_codes.h" -#include "ui/gfx/point.h" - -class OSExchangeData; - -namespace ui { - -class View; - -class Event { - public: - EventType type() const { return type_; } - int flags() const { return flags_; } - void set_flags(int flags) { flags_ = flags; } - - // The following methods return true if the respective keys were pressed at - // the time the event was created. - bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; } - bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; } - bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; } - bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; } - - // Return a mask of active modifier keycodes from - // ui/base/keycodes/keyboard_codes.h - int GetModifiers() const; - - // Returns true if the event is any kind of mouse event. - bool IsMouseEvent() const { - return type_ == ET_MOUSE_PRESSED || - type_ == ET_MOUSE_RELEASED || - type_ == ET_MOUSE_MOVED || - type_ == ET_MOUSE_EXITED || - type_ == ET_MOUSEWHEEL; - } - - protected: - Event(EventType type, int flags); - - private: - EventType type_; - int flags_; - - DISALLOW_COPY_AND_ASSIGN(Event); -}; - -class LocatedEvent : public Event { - public: - int x() const { return location_.x(); } - int y() const { return location_.y(); } - const gfx::Point& location() const { return location_; } - - protected: - // Constructors called from subclasses. - - // Simple initialization from cracked metadata. - LocatedEvent(EventType type, const gfx::Point& location, int flags); - - // During event processing, event locations are translated from the - // coordinates of a source View to a target as the tree is descended. This - // translation occurs by constructing a new event from another event object, - // specifying a |source| and |target| View to facilitate coordinate - // conversion. Events that are processed in this manner will have a similar - // constructor that calls into this one. - LocatedEvent(const LocatedEvent& other, View* source, View* target); - - private: - gfx::Point location_; - - DISALLOW_COPY_AND_ASSIGN(LocatedEvent); -}; - -class MouseEvent : public LocatedEvent { - public: - explicit MouseEvent(const ui::NativeEvent& native_event); - - MouseEvent(const MouseEvent& other, View* source, View* target); - - // Conveniences to quickly test what button is down: - bool IsOnlyLeftMouseButton() const { - return (flags() & EF_LEFT_BUTTON_DOWN) && - !(flags() & (EF_MIDDLE_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN)); - } - bool IsLeftMouseButton() const { - return (flags() & EF_LEFT_BUTTON_DOWN) != 0; - } - bool IsOnlyMiddleMouseButton() const { - return (flags() & EF_MIDDLE_BUTTON_DOWN) && - !(flags() & (EF_LEFT_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN)); - } - bool IsMiddleMouseButton() const { - return (flags() & EF_MIDDLE_BUTTON_DOWN) != 0; - } - bool IsOnlyRightMouseButton() const { - return (flags() & EF_RIGHT_BUTTON_DOWN) && - !(flags() & (EF_LEFT_BUTTON_DOWN | EF_MIDDLE_BUTTON_DOWN)); - } - bool IsRightMouseButton() const { - return (flags() & EF_RIGHT_BUTTON_DOWN) != 0; - } - - private: - DISALLOW_COPY_AND_ASSIGN(MouseEvent); -}; - -class KeyEvent : public Event { - public: - explicit KeyEvent(const ui::NativeEvent& native_event); - - KeyboardCode key_code() const { return key_code_; } - - private: - KeyboardCode key_code_; - - DISALLOW_COPY_AND_ASSIGN(KeyEvent); -}; - -class MouseWheelEvent : public LocatedEvent { - public: - explicit MouseWheelEvent(const ui::NativeEvent& native_event); - - int offset() const { return offset_; } - - private: - int offset_; - - DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); -}; - -/* -class DropTargetEvent : public LocatedEvent { - public: - explicit DropTargetEvent(const ui::NativeEvent& native_event); - - const OSExchangeData& data() const { return data_; } - int source_operations() const { return source_operations_; } - - private: - const OSExchangeData& data_; - int source_operations_; - - DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); -}; -*/ - -} // namespace ui - -#endif // UI_VIEWS_EVENTS_EVENT_H_ diff --git a/ui/views/events/focus_event.cc b/ui/views/events/focus_event.cc deleted file mode 100644 index 4a05999..0000000 --- a/ui/views/events/focus_event.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/events/focus_event.h" - -namespace ui { - -//////////////////////////////////////////////////////////////////////////////// -// FocusEvent, public: - -FocusEvent::FocusEvent(Type type, Reason reason, TraversalDirection direction) - : type_(type), - reason_(reason), - direction_(direction), - Event(ET_FOCUS_CHANGE, 0) { -} - -} // namespace ui diff --git a/ui/views/events/focus_event.h b/ui/views/events/focus_event.h deleted file mode 100644 index 377c3f7..0000000 --- a/ui/views/events/focus_event.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_EVENTS_FOCUS_EVENT_H_ -#define UI_VIEWS_EVENTS_FOCUS_EVENT_H_ -#pragma once - -#include "base/basictypes.h" -#include "ui/views/events/event.h" - -namespace ui { - -class FocusEvent : public Event { - public: - enum Type { - TYPE_FOCUS_IN, // Target View did gain focus - TYPE_FOCUS_OUT // Target View will lose focus - }; - - enum Reason { - REASON_TRAVERSAL, // Focus change occurred because of a tab-traversal - REASON_RESTORE, // Focus was restored (e.g. window activation). - REASON_DIRECT // Focus was directly set (e.g. with mouse click). - }; - - enum TraversalDirection { - DIRECTION_NONE, - DIRECTION_FORWARD, - DIRECTION_REVERSE - }; - - FocusEvent(Type type, - Reason reason, - TraversalDirection direction); - - Type type() const { return type_; } - Reason reason() const { return reason_; } - TraversalDirection direction() const { return direction_; } - - private: - Type type_; - Reason reason_; - TraversalDirection direction_; - - DISALLOW_COPY_AND_ASSIGN(FocusEvent); -}; - -} // namespace ui - -#endif // UI_VIEWS_EVENTS_FOCUS_EVENT_H_ diff --git a/ui/views/focus/accelerator_handler.h b/ui/views/focus/accelerator_handler.h deleted file mode 100644 index 3d0c5e0..0000000 --- a/ui/views/focus/accelerator_handler.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_FOCUS_ACCELERATOR_HANDLER_H_ -#define UI_VIEWS_FOCUS_ACCELERATOR_HANDLER_H_ -#pragma once - -#include "build/build_config.h" - -#if defined(TOOLKIT_USES_GTK) -#include <gdk/gdk.h> -#endif - -#include <set> -#include <vector> - -#include "base/message_loop.h" - -namespace ui { - -#if defined(TOUCH_UI) -// Dispatch an XEvent to the RootView. Return true if the event was dispatched -// and handled, false otherwise. -bool DispatchXEvent(XEvent* xevent); - -// Keep a list of touch devices so that it is possible to determine if a pointer -// event is a touch-event or a mouse-event. -void SetTouchDeviceList(std::vector<unsigned int>& devices); -#endif // TOUCH_UI - -//////////////////////////////////////////////////////////////////////////////// -// AcceleratorHandler class -// -// An object that pre-screens all UI messages for potential accelerators. -// Registered accelerators are processed regardless of focus within a given -// Widget or Window. -// -// This processing is done at the Dispatcher level rather than on the Widget -// because of the global nature of this processing, and the fact that not all -// controls within a window need to be Widgets - some are native controls from -// the underlying toolkit wrapped by NativeViewHost. -// -class AcceleratorHandler : public MessageLoopForUI::Dispatcher { - public: - AcceleratorHandler(); - // Dispatcher method. This returns true if an accelerator was processed by the - // focus manager -#if defined(OS_WIN) - virtual bool Dispatch(const MSG& msg); -#elif defined(TOUCH_UI) - virtual MesasgePumpDispatcher::DispatchStatus Dispatch(XEvent* xev); -#else - virtual bool Dispatch(GdkEvent* event); -#endif - - private: -#if defined(OS_WIN) - // The keys currently pressed and consumed by the FocusManager. - std::set<WPARAM> pressed_keys_; -#endif - - DISALLOW_COPY_AND_ASSIGN(AcceleratorHandler); -}; - -} // namespace ui - -#endif // UI_VIEWS_FOCUS_ACCELERATOR_HANDLER_H_ diff --git a/ui/views/focus/accelerator_handler_win.cc b/ui/views/focus/accelerator_handler_win.cc deleted file mode 100644 index ab059ec..0000000 --- a/ui/views/focus/accelerator_handler_win.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/focus/accelerator_handler.h" - -#include "ui/base/keycodes/keyboard_codes.h" -#include "ui/base/keycodes/keyboard_code_conversion_win.h" -#include "ui/views/events/event.h" -#include "ui/views/focus/focus_manager.h" -#include "ui/views/widget/widget.h" - -namespace ui { - -AcceleratorHandler::AcceleratorHandler() { -} - -bool AcceleratorHandler::Dispatch(const MSG& msg) { - bool process_message = true; - - if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { - Widget* widget = Widget::GetTopLevelWidgetForNativeView(msg.hwnd); - FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL; - if (focus_manager) { - switch (msg.message) { - case WM_KEYDOWN: - case WM_SYSKEYDOWN: { - process_message = focus_manager->OnKeyEvent(KeyEvent(msg)); - if (!process_message) { - // Record that this key is pressed so we can remember not to - // translate and dispatch the associated WM_KEYUP. - pressed_keys_.insert(msg.wParam); - } - break; - } - case WM_KEYUP: - case WM_SYSKEYUP: { - std::set<WPARAM>::iterator iter = pressed_keys_.find(msg.wParam); - if (iter != pressed_keys_.end()) { - // Don't translate/dispatch the KEYUP since we have eaten the - // associated KEYDOWN. - pressed_keys_.erase(iter); - return true; - } - break; - } - } - } - } - - if (process_message) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - return true; -} - -} // namespace ui diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc deleted file mode 100644 index efe65b1..0000000 --- a/ui/views/focus/focus_manager.cc +++ /dev/null @@ -1,461 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/focus/focus_manager.h" - -#include <algorithm> - -#include "build/build_config.h" - -#if defined(TOOLKIT_USES_GTK) -#include <gtk/gtk.h> -#endif - -#include "base/logging.h" -#include "ui/base/keycodes/keyboard_codes.h" -#include "ui/views/events/event.h" -#include "ui/views/focus/focus_search.h" -#include "ui/views/view.h" -#include "ui/views/widget/root_view.h" -#include "ui/views/widget/native_widget.h" -#include "ui/views/widget/widget.h" - -namespace ui { - -namespace { - -FocusEvent::TraversalDirection DirectionFromBool(bool forward) { - return forward ? FocusEvent::DIRECTION_FORWARD - : FocusEvent::DIRECTION_REVERSE; -} - -FocusEvent::TraversalDirection DirectionFromKeyEvent(const KeyEvent& event) { - return DirectionFromBool(!event.IsShiftDown()); -} - -bool IsTraverseForward(FocusEvent::TraversalDirection direction) { - return direction == FocusEvent::DIRECTION_FORWARD; -} - -#if defined(OS_WIN) -// Don't allow focus traversal if the root window is not part of the active -// window hierarchy as this would mean we have no focused view and would focus -// the first focusable view. -bool CanTraverseFocus(Widget* widget) { - HWND top_window = widget->native_widget()->GetNativeView(); - HWND active_window = ::GetActiveWindow(); - return active_window == top_window || ::IsChild(active_window, top_window); -} -#else -bool CanTraverseFocus(Widget* widget) { - return true; -} -#endif - -} - -// FocusManager::WidgetFocusManager --------------------------------- - -void FocusManager::WidgetFocusManager::AddFocusChangeListener( - WidgetFocusChangeListener* listener) { - DCHECK(std::find(focus_change_listeners_.begin(), - focus_change_listeners_.end(), listener) == - focus_change_listeners_.end()) << - "Adding a WidgetFocusChangeListener twice."; - focus_change_listeners_.push_back(listener); -} - -void FocusManager::WidgetFocusManager::RemoveFocusChangeListener( - WidgetFocusChangeListener* listener) { - WidgetFocusChangeListenerList::iterator iter(std::find( - focus_change_listeners_.begin(), - focus_change_listeners_.end(), - listener)); - if (iter != focus_change_listeners_.end()) { - focus_change_listeners_.erase(iter); - } else { - NOTREACHED() << - "Attempting to remove an unregistered WidgetFocusChangeListener."; - } -} - -void FocusManager::WidgetFocusManager::OnWidgetFocusEvent( - gfx::NativeView focused_before, - gfx::NativeView focused_now) { - if (!enabled_) - return; - - // Perform a safe iteration over the focus listeners, as the array - // may change during notification. - WidgetFocusChangeListenerList local_listeners(focus_change_listeners_); - WidgetFocusChangeListenerList::iterator iter(local_listeners.begin()); - for (;iter != local_listeners.end(); ++iter) { - (*iter)->NativeFocusWillChange(focused_before, focused_now); - } -} - -// static -FocusManager::WidgetFocusManager* -FocusManager::WidgetFocusManager::GetInstance() { - return Singleton<WidgetFocusManager>::get(); -} - -FocusManager::WidgetFocusManager::WidgetFocusManager() : enabled_(true) {} - -FocusManager::WidgetFocusManager::~WidgetFocusManager() {} - -//////////////////////////////////////////////////////////////////////////////// -// FocusManager, public: - -FocusManager::FocusManager(Widget* widget) - : widget_(widget), - focused_view_(NULL) { - DCHECK(widget_); -} - -FocusManager::~FocusManager() { - // If there are still registered FocusChange listeners, chances are they were - // leaked so warn about them. - DCHECK(focus_change_listeners_.empty()); -} - -// static -FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { - return WidgetFocusManager::GetInstance(); -} - -bool FocusManager::OnKeyEvent(const KeyEvent& event) { - // If the focused view wants to process the key event as is, let it be. - // On Linux we always dispatch key events to the focused view first, so - // we should not do this check here. See also NativeWidgetGtk::OnKeyEvent(). - if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event)) - return true; - - // Intercept Tab related messages for focus traversal. - if (CanTraverseFocus(widget_) && IsTabTraversalKeyEvent(event)) { - AdvanceFocus(DirectionFromKeyEvent(event)); - return false; - } - - // Intercept arrow key messages to switch between grouped views. - // TODO(beng): Perhaps make this a FocusTraversable that is created for - // Views that have a group set? - ui::KeyboardCode key_code = event.key_code(); - if (focused_view_ && focused_view_->group() != -1 && - (key_code == ui::VKEY_UP || key_code == ui::VKEY_DOWN || - key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) { - bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN); - std::vector<View*> views; - focused_view_->parent()->GetViewsInGroup(focused_view_->group(), &views); - std::vector<View*>::const_iterator iter = std::find(views.begin(), - views.end(), - focused_view_); - DCHECK(iter != views.end()); - int index = static_cast<int>(iter - views.begin()); - index += next ? 1 : -1; - if (index < 0) { - index = static_cast<int>(views.size()) - 1; - } else if (index >= static_cast<int>(views.size())) { - index = 0; - } - SetFocusedViewWithReasonAndDirection(views[index], - FocusEvent::REASON_TRAVERSAL, - DirectionFromBool(next)); - return false; - } - - // Process keyboard accelerators. - // If the key combination matches an accelerator, the accelerator is - // triggered, otherwise the key event is processed as usual. - Accelerator accelerator(event.key_code(), event.GetModifiers()); - if (ProcessAccelerator(accelerator)) { - // If a shortcut was activated for this keydown message, do not propagate - // the event further. - return false; - } - return true; -} - -bool FocusManager::ContainsView(View* view) const { - Widget* widget = view->GetWidget(); - return widget ? widget->GetFocusManager() == this : false; -} - -void FocusManager::RemoveView(View* view) { - // Clear focus if the removed child was focused. - if (focused_view_ == view) - ClearFocus(); -} - -void FocusManager::AdvanceFocus(FocusEvent::TraversalDirection direction) { - View* view = GetNextFocusableView(focused_view_, direction, false); - // Note: Do not skip this next block when v == focused_view_. If the user - // tabs past the last focusable element in a web page, we'll get here, and if - // the TabContentsContainerView is the only focusable view (possible in - // full-screen mode), we need to run this block in order to cycle around to - // the first element on the page. - if (view) { - SetFocusedViewWithReasonAndDirection(view, FocusEvent::REASON_TRAVERSAL, - direction); - } -} - -void FocusManager::SetFocusedViewWithReasonAndDirection( - View* view, - FocusEvent::Reason reason, - FocusEvent::TraversalDirection direction) { - if (focused_view_ == view) - return; - - View* prev_focused_view = focused_view_; - if (focused_view_) { - focused_view_->OnBlur( - FocusEvent(FocusEvent::TYPE_FOCUS_OUT, reason, direction)); - focused_view_->Invalidate(); - } - - // Notified listeners that the focus changed. - FocusChangeListenerList::const_iterator iter; - for (iter = focus_change_listeners_.begin(); - iter != focus_change_listeners_.end(); ++iter) { - (*iter)->FocusWillChange(prev_focused_view, view); - } - - focused_view_ = view; - - if (view) { - view->Invalidate(); - view->OnFocus(FocusEvent(FocusEvent::TYPE_FOCUS_IN, reason, direction)); - // The view might be deleted now. - } -} - -void FocusManager::ClearFocus() { - SetFocusedView(NULL); - widget_->native_widget()->FocusNativeView(NULL); -} - -void FocusManager::ValidateFocusedView() { - if (focused_view_) { - if (!ContainsView(focused_view_)) - ClearFocus(); - } -} - -void FocusManager::RegisterAccelerator( - const Accelerator& accelerator, - AcceleratorTarget* target) { - AcceleratorTargetList& targets = accelerators_[accelerator]; - DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end()) - << "Registering the same target multiple times"; - targets.push_front(target); -} - -void FocusManager::UnregisterAccelerator(const Accelerator& accelerator, - AcceleratorTarget* target) { - AcceleratorMap::iterator map_iter = accelerators_.find(accelerator); - if (map_iter == accelerators_.end()) { - NOTREACHED() << "Unregistering non-existing accelerator"; - return; - } - - AcceleratorTargetList* targets = &map_iter->second; - AcceleratorTargetList::iterator target_iter = - std::find(targets->begin(), targets->end(), target); - if (target_iter == targets->end()) { - NOTREACHED() << "Unregistering accelerator for wrong target"; - return; - } - - targets->erase(target_iter); -} - -void FocusManager::UnregisterAccelerators(AcceleratorTarget* target) { - for (AcceleratorMap::iterator map_iter = accelerators_.begin(); - map_iter != accelerators_.end(); ++map_iter) { - AcceleratorTargetList* targets = &map_iter->second; - targets->remove(target); - } -} - -bool FocusManager::ProcessAccelerator(const Accelerator& accelerator) { - AcceleratorMap::iterator map_iter = accelerators_.find(accelerator); - if (map_iter != accelerators_.end()) { - // We have to copy the target list here, because an AcceleratorPressed - // event handler may modify the list. - AcceleratorTargetList targets(map_iter->second); - for (AcceleratorTargetList::iterator iter = targets.begin(); - iter != targets.end(); ++iter) { - if ((*iter)->AcceleratorPressed(accelerator)) - return true; - } - } - return false; -} - -void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { - DCHECK(std::find(focus_change_listeners_.begin(), - focus_change_listeners_.end(), listener) == - focus_change_listeners_.end()) << "Adding a listener twice."; - focus_change_listeners_.push_back(listener); -} - -void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { - FocusChangeListenerList::iterator place = - std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), - listener); - if (place == focus_change_listeners_.end()) { - NOTREACHED() << "Removing a listener that isn't registered."; - return; - } - focus_change_listeners_.erase(place); -} - -AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( - const Accelerator& accelerator) const { - AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator); - if (map_iter == accelerators_.end() || map_iter->second.empty()) - return NULL; - return map_iter->second.front(); -} - -// static -bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) { - return key_event.key_code() == ui::VKEY_TAB && - !key_event.IsControlDown(); -} - -//////////////////////////////////////////////////////////////////////////////// -// FocusManager, private: - -View* FocusManager::GetNextFocusableView( - View* original_starting_view, - FocusEvent::TraversalDirection direction, - bool dont_loop) { - FocusTraversable* focus_traversable = NULL; - - // Let's re-validate the focused view. - ValidateFocusedView(); - - View* starting_view = NULL; - if (original_starting_view) { - // Search up the containment hierarchy to see if a view is acting as - // a pane, and wants to implement its own focus traversable to keep - // the focus trapped within that pane. - View* pane_search = original_starting_view; - while (pane_search) { - focus_traversable = pane_search->GetPaneFocusTraversable(); - if (focus_traversable) { - starting_view = original_starting_view; - break; - } - pane_search = pane_search->parent(); - } - - if (!focus_traversable) { - if (IsTraverseForward(direction)) { - // If the starting view has a focus traversable, use it. - // This is the case with NativeWidgetWins for example. - focus_traversable = original_starting_view->GetFocusTraversable(); - - // Otherwise default to the root view. - if (!focus_traversable) { - focus_traversable = - original_starting_view->GetWidget()->GetFocusTraversable(); - starting_view = original_starting_view; - } - } else { - // When you are going back, starting view's FocusTraversable - // should not be used. - focus_traversable = - original_starting_view->GetWidget()->GetFocusTraversable(); - starting_view = original_starting_view; - } - } - } else { - focus_traversable = widget_->GetFocusTraversable(); - } - - // Traverse the FocusTraversable tree down to find the focusable view. - View* v = FindFocusableView(focus_traversable, starting_view, direction); - if (v) { - return v; - } else { - // Let's go up in the FocusTraversable tree. - FocusTraversable* parent_focus_traversable = - focus_traversable->GetFocusTraversableParent(); - starting_view = focus_traversable->GetFocusTraversableParentView(); - while (parent_focus_traversable) { - FocusTraversable* new_focus_traversable = NULL; - View* new_starting_view = NULL; - // When we are going backward, the parent view might gain the next focus. - bool check_starting_view = !IsTraverseForward(direction); - v = parent_focus_traversable->GetFocusSearch()->FindNextFocusableView( - starting_view, !IsTraverseForward(direction), FocusSearch::UP, - check_starting_view, &new_focus_traversable, &new_starting_view); - - if (new_focus_traversable) { - DCHECK(!v); - - // There is a FocusTraversable, traverse it down. - v = FindFocusableView(new_focus_traversable, NULL, direction); - } - - if (v) - return v; - - starting_view = focus_traversable->GetFocusTraversableParentView(); - parent_focus_traversable = - parent_focus_traversable->GetFocusTraversableParent(); - } - - // If we get here, we have reached the end of the focus hierarchy, let's - // loop. Make sure there was at least a view to start with, to prevent - // infinitely looping in empty windows. - if (!dont_loop && original_starting_view) { - // Easy, just clear the selection and press tab again. - // By calling with NULL as the starting view, we'll start from the - // top_root_view. - return GetNextFocusableView(NULL, direction, true); - } - } - return NULL; -} - -// Find the next focusable view for the specified FocusTraversable, starting at -// the specified view, traversing down the FocusTraversable hierarchy in -// |direction|. -View* FocusManager::FindFocusableView( - FocusTraversable* focus_traversable, - View* starting_view, - FocusEvent::TraversalDirection direction) { - FocusTraversable* new_focus_traversable = NULL; - View* new_starting_view = NULL; - View* v = focus_traversable->GetFocusSearch()->FindNextFocusableView( - starting_view, - !IsTraverseForward(direction), - FocusSearch::DOWN, - false, - &new_focus_traversable, - &new_starting_view); - - // Let's go down the FocusTraversable tree as much as we can. - while (new_focus_traversable) { - DCHECK(!v); - focus_traversable = new_focus_traversable; - starting_view = new_starting_view; - new_focus_traversable = NULL; - starting_view = NULL; - v = focus_traversable->GetFocusSearch()->FindNextFocusableView( - starting_view, - !IsTraverseForward(direction), - FocusSearch::DOWN, - false, - &new_focus_traversable, - &new_starting_view); - } - return v; -} - -} // namespace ui diff --git a/ui/views/focus/focus_manager.h b/ui/views/focus/focus_manager.h deleted file mode 100644 index 2236619..0000000 --- a/ui/views/focus/focus_manager.h +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ -#define UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ -#pragma once - -#include <list> -#include <map> -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/singleton.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/views/events/accelerator.h" -#include "ui/views/events/focus_event.h" - -// The FocusManager class is used to handle focus traversal, store/restore -// focused views and handle keyboard accelerators. -// -// There are 2 types of focus: -// - the native focus, which is the focus that an gfx::NativeView has. -// - the view focus, which is the focus that a views::View has. -// -// Each native view must register with their Focus Manager so the focus manager -// gets notified when they are focused (and keeps track of the native focus) and -// as well so that the tab key events can be intercepted. -// They can provide when they register a View that is kept in synch in term of -// focus. This is used in NativeControl for example, where a View wraps an -// actual native window. -// This is already done for you if you subclass the NativeControl class or if -// you use the NativeViewHost class. -// -// When creating a top window (derived from views::Widget) that is not a child -// window, it creates and owns a FocusManager to manage the focus for itself and -// all its child windows. -// -// The FocusTraversable interface exposes the methods a class should implement -// in order to be able to be focus traversed when tab key is pressed. -// RootViews implement FocusTraversable. -// The FocusManager contains a top FocusTraversable instance, which is the top -// RootView. -// -// If you just use views, then the focus traversal is handled for you by the -// RootView. The default traversal order is the order in which the views have -// been added to their container. You can modify this order by using the View -// method SetNextFocusableView(). -// -// If you are embedding a native view containing a nested RootView (for example -// by adding a NativeControl that contains a NativeWidgetWin as its native -// component), then you need to: -// - override the View::GetFocusTraversable() method in your outer component. -// It should return the RootView of the inner component. This is used when -// the focus traversal traverse down the focus hierarchy to enter the nested -// RootView. In the example mentioned above, the NativeControl overrides -// GetFocusTraversable() and returns hwnd_view_container_->GetRootView(). -// - call RootView::SetFocusTraversableParent() on the nested RootView and point -// it to the outter RootView. This is used when the focus goes out of the -// nested RootView. In the example: -// hwnd_view_container_->GetRootView()->SetFocusTraversableParent( -// native_control->GetRootView()); -// - call RootView::SetFocusTraversableParentView() on the nested RootView with -// the parent view that directly contains the native window. This is needed -// when traversing up from the nested RootView to know which view to start -// with when going to the next/previous view. -// In our example: -// hwnd_view_container_->GetRootView()->SetFocusTraversableParent( -// native_control); -// -// Note that FocusTraversable do not have to be RootViews: AccessibleToolbarView -// is FocusTraversable. - -namespace ui { - -class FocusSearch; -class RootView; -class View; -class Widget; - -// The FocusTraversable interface is used by components that want to process -// focus traversal events (due to Tab/Shift-Tab key events). -class FocusTraversable { - public: - // Return a FocusSearch object that implements the algorithm to find - // the next or previous focusable view. - virtual const FocusSearch* GetFocusSearch() const = 0; - - // Should return the parent FocusTraversable. - // The top RootView which is the top FocusTraversable returns NULL. - virtual FocusTraversable* GetFocusTraversableParent() const = 0; - - // This should return the View this FocusTraversable belongs to. - // It is used when walking up the view hierarchy tree to find which view - // should be used as the starting view for finding the next/previous view. - virtual View* GetFocusTraversableParentView() const = 0; - - protected: - virtual ~FocusTraversable() {} -}; - -// This interface should be implemented by classes that want to be notified when -// the focus is about to change. See the Add/RemoveFocusChangeListener methods. -class FocusChangeListener { - public: - virtual void FocusWillChange(View* focused_before, View* focused_now) = 0; - - protected: - virtual ~FocusChangeListener() {} -}; - -// This interface should be implemented by classes that want to be notified when -// the native focus is about to change. Listeners implementing this interface -// will be invoked for all native focus changes across the entire Chrome -// application. FocusChangeListeners are only called for changes within the -// children of a single top-level native-view. -class WidgetFocusChangeListener { - public: - virtual void NativeFocusWillChange(gfx::NativeView focused_before, - gfx::NativeView focused_now) = 0; - - protected: - virtual ~WidgetFocusChangeListener() {} -}; - -class FocusManager { - public: - class WidgetFocusManager { - public: - // Returns the singleton instance. - static WidgetFocusManager* GetInstance(); - - // Adds/removes a WidgetFocusChangeListener |listener| to the set of - // active listeners. - void AddFocusChangeListener(WidgetFocusChangeListener* listener); - void RemoveFocusChangeListener(WidgetFocusChangeListener* listener); - - // To be called when native-focus shifts from |focused_before| to - // |focused_now|. - // TODO(port) : Invocations to this routine are only implemented for - // the Win32 platform. Calls need to be placed appropriately for - // non-Windows environments. - void OnWidgetFocusEvent(gfx::NativeView focused_before, - gfx::NativeView focused_now); - - // Enable/Disable notification of registered listeners during calls - // to OnWidgetFocusEvent. Used to prevent unwanted focus changes from - // propagating notifications. - void EnableNotifications() { enabled_ = true; } - void DisableNotifications() { enabled_ = false; } - - private: - WidgetFocusManager(); - ~WidgetFocusManager(); - - typedef std::vector<WidgetFocusChangeListener*> - WidgetFocusChangeListenerList; - WidgetFocusChangeListenerList focus_change_listeners_; - - bool enabled_; - - friend struct DefaultSingletonTraits<WidgetFocusManager>; - DISALLOW_COPY_AND_ASSIGN(WidgetFocusManager); - }; - - explicit FocusManager(Widget* widget); - virtual ~FocusManager(); - - // Returns the global WidgetFocusManager instance for the running application. - static WidgetFocusManager* GetWidgetFocusManager(); - - // Processes the passed key event for accelerators and tab traversal. - // Returns false if the event has been consumed and should not be processed - // further. - bool OnKeyEvent(const KeyEvent& event); - - // Returns true is the specified is part of the hierarchy of the window - // associated with this FocusManager. - bool ContainsView(View* view) const; - - // Stops tracking this View in the focus manager. If the View is focused, - // focus is cleared. - void RemoveView(View* view); - - // Advances the focus (backward if reverse is true). - void AdvanceFocus(FocusEvent::TraversalDirection direction); - - // The FocusManager keeps track of the focused view within a RootView. - View* focused_view() const { return focused_view_; } - - // Low-level methods to force the focus to change. If the focus change should - // only happen if the view is currently focusable, enabled, and visible, call - // view->RequestFocus(). - void SetFocusedViewWithReasonAndDirection( - View* view, - FocusEvent::Reason reason, - FocusEvent::TraversalDirection direction); - void SetFocusedView(View* view) { - SetFocusedViewWithReasonAndDirection(view, FocusEvent::REASON_DIRECT, - FocusEvent::DIRECTION_NONE); - } - - // Clears the focused view. The window associated with the top root view gets - // the native focus (so we still get keyboard events). - void ClearFocus(); - - // Validates the focused view, clearing it if the window it belongs too is not - // attached to the window hierarchy anymore. - void ValidateFocusedView(); - - // Register a keyboard accelerator for the specified target. If multiple - // targets are registered for an accelerator, a target registered later has - // higher priority. - // Note that we are currently limited to accelerators that are either: - // - a key combination including Ctrl or Alt - // - the escape key - // - the enter key - // - any F key (F1, F2, F3 ...) - // - any browser specific keys (as available on special keyboards) - void RegisterAccelerator(const Accelerator& accelerator, - AcceleratorTarget* target); - - // Unregister the specified keyboard accelerator for the specified target. - void UnregisterAccelerator(const Accelerator& accelerator, - AcceleratorTarget* target); - - // Unregister all keyboard accelerator for the specified target. - void UnregisterAccelerators(AcceleratorTarget* target); - - // Activate the target associated with the specified accelerator. - // First, AcceleratorPressed handler of the most recently registered target - // is called, and if that handler processes the event (i.e. returns true), - // this method immediately returns. If not, we do the same thing on the next - // target, and so on. - // Returns true if an accelerator was activated. - bool ProcessAccelerator(const Accelerator& accelerator); - - // Adds/removes a listener. The FocusChangeListener is notified every time - // the focused view is about to change. - void AddFocusChangeListener(FocusChangeListener* listener); - void RemoveFocusChangeListener(FocusChangeListener* listener); - - // Returns the AcceleratorTarget that should be activated for the specified - // keyboard accelerator, or NULL if no view is registered for that keyboard - // accelerator. - AcceleratorTarget* GetCurrentTargetForAccelerator( - const Accelerator& accelertor) const; - - // Convenience method that returns true if the passed |key_event| should - // trigger tab traversal (if it is a TAB key press with or without SHIFT - // pressed). - static bool IsTabTraversalKeyEvent(const KeyEvent& key_event); - - private: - // Returns the next focusable view. - View* GetNextFocusableView(View* starting_view, - FocusEvent::TraversalDirection direction, - bool dont_loop); - - // Returns the focusable view found in the FocusTraversable specified starting - // at the specified view. This traverses down along the FocusTraversable - // hierarchy. - // Returns NULL if no focusable view were found. - View* FindFocusableView(FocusTraversable* focus_traversable, - View* starting_view, - FocusEvent::TraversalDirection direction); - - // The top-level Widget this FocusManager is associated with. - Widget* widget_; - - // The view that currently is focused. - View* focused_view_; - - // The accelerators and associated targets. - typedef std::list<AcceleratorTarget*> AcceleratorTargetList; - typedef std::map<Accelerator, AcceleratorTargetList> AcceleratorMap; - AcceleratorMap accelerators_; - - // The list of registered FocusChange listeners. - typedef std::vector<FocusChangeListener*> FocusChangeListenerList; - FocusChangeListenerList focus_change_listeners_; - - DISALLOW_COPY_AND_ASSIGN(FocusManager); -}; - -// A basic helper class that is used to disable native focus change -// notifications within a scope. -class AutoNativeNotificationDisabler { - public: - AutoNativeNotificationDisabler() { - FocusManager::GetWidgetFocusManager()->DisableNotifications(); - } - - ~AutoNativeNotificationDisabler() { - FocusManager::GetWidgetFocusManager()->EnableNotifications(); - } - private: - DISALLOW_COPY_AND_ASSIGN(AutoNativeNotificationDisabler); -}; - -} // namespace ui - -#endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_H_ diff --git a/ui/views/focus/focus_search.cc b/ui/views/focus/focus_search.cc deleted file mode 100644 index 083fc7c..0000000 --- a/ui/views/focus/focus_search.cc +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/logging.h" -#include "ui/views/focus/focus_manager.h" -#include "ui/views/focus/focus_search.h" -#include "ui/views/view.h" - -namespace ui { - -FocusSearch::FocusSearch(View* root, bool cycle, bool accessibility_mode) - : root_(root), - cycle_(cycle), - accessibility_mode_(accessibility_mode) { -} - -View* FocusSearch::FindNextFocusableView(View* starting_view, - bool reverse, - Direction direction, - bool check_starting_view, - FocusTraversable** focus_traversable, - View** focus_traversable_view) const { - *focus_traversable = NULL; - *focus_traversable_view = NULL; - - if (root_->children_empty()) { - NOTREACHED(); - // Nothing to focus on here. - return NULL; - } - - View* initial_starting_view = starting_view; - int starting_view_group = -1; - if (starting_view) - starting_view_group = starting_view->group(); - - if (!starting_view) { - // Default to the first/last child - starting_view = - reverse ? - root_->child_at(root_->children_size() - 1) : - root_->child_at(0); - // If there was no starting view, then the one we select is a potential - // focus candidate. - check_starting_view = true; - } else { - // The starting view should be a direct or indirect child of the root. - DCHECK(root_->Contains(*starting_view)); - } - - View* v = NULL; - if (!reverse) { - v = FindNextFocusableViewImpl(starting_view, check_starting_view, - true, - (direction == DOWN) ? true : false, - starting_view_group, - focus_traversable, - focus_traversable_view); - } else { - // If the starting view is focusable, we don't want to go down, as we are - // traversing the view hierarchy tree bottom-up. - bool can_go_down = (direction == DOWN) && !IsFocusable(starting_view); - v = FindPreviousFocusableViewImpl(starting_view, check_starting_view, - true, - can_go_down, - starting_view_group, - focus_traversable, - focus_traversable_view); - } - - // Don't set the focus to something outside of this view hierarchy. - if (v && v != root_ && !root_->Contains(*v)) - v = NULL; - - // If |cycle_| is true, prefer to keep cycling rather than returning NULL. - if (cycle_ && !v && initial_starting_view) { - v = FindNextFocusableView(NULL, reverse, direction, check_starting_view, - focus_traversable, focus_traversable_view); - DCHECK(IsFocusable(v)); - return v; - } - - // Doing some sanity checks. - if (v) { - DCHECK(IsFocusable(v)); - return v; - } - if (*focus_traversable) { - DCHECK(*focus_traversable_view); - return NULL; - } - // Nothing found. - return NULL; -} - -bool FocusSearch::IsViewFocusableCandidate(View* v, int skip_group_id) const { - return IsFocusable(v) && - (v->IsGroupFocusTraversable() || skip_group_id == -1 || - v->group() != skip_group_id); -} - -bool FocusSearch::IsFocusable(View* v) const { - if (accessibility_mode_) - return v && v->IsAccessibilityFocusableInRootView(); - - return v && v->IsFocusableInRootView(); -} - -View* FocusSearch::FindSelectedViewForGroup(View* view) const { - // No group for that view. - if (view->IsGroupFocusTraversable() || view->group() == -1) - return view; - - View* selected_view = view->GetSelectedViewForGroup(view->group()); - if (selected_view) - return selected_view; - - // No view selected for that group, default to the specified view. - return view; -} - -View* FocusSearch::GetParent(View* v) const { - return root_->Contains(*v) ? v->parent() : NULL; -} - -// Strategy for finding the next focusable view: -// - keep going down the first child, stop when you find a focusable view or -// a focus traversable view (in that case return it) or when you reach a view -// with no children. -// - go to the right sibling and start the search from there (by invoking -// FindNextFocusableViewImpl on that view). -// - if the view has no right sibling, go up the parents until you find a parent -// with a right sibling and start the search from there. -View* FocusSearch::FindNextFocusableViewImpl( - View* starting_view, - bool check_starting_view, - bool can_go_up, - bool can_go_down, - int skip_group_id, - FocusTraversable** focus_traversable, - View** focus_traversable_view) const { - if (check_starting_view) { - if (IsViewFocusableCandidate(starting_view, skip_group_id)) { - View* v = FindSelectedViewForGroup(starting_view); - // The selected view might not be focusable (if it is disabled for - // example). - if (IsFocusable(v)) - return v; - } - - *focus_traversable = starting_view->GetFocusTraversable(); - if (*focus_traversable) { - *focus_traversable_view = starting_view; - return NULL; - } - } - - // First let's try the left child. - if (can_go_down) { - if (!starting_view->children_empty()) { - View* v = FindNextFocusableViewImpl(starting_view->child_at(0), - true, false, true, skip_group_id, - focus_traversable, - focus_traversable_view); - if (v || *focus_traversable) - return v; - } - } - - // Then try the right sibling. - View* sibling = starting_view->GetNextFocusableView(); - if (sibling) { - View* v = FindNextFocusableViewImpl(sibling, - true, false, true, skip_group_id, - focus_traversable, - focus_traversable_view); - if (v || *focus_traversable) - return v; - } - - // Then go up to the parent sibling. - if (can_go_up) { - View* parent = GetParent(starting_view); - while (parent) { - sibling = parent->GetNextFocusableView(); - if (sibling) { - return FindNextFocusableViewImpl(sibling, - true, true, true, - skip_group_id, - focus_traversable, - focus_traversable_view); - } - parent = GetParent(parent); - } - } - - // We found nothing. - return NULL; -} - -// Strategy for finding the previous focusable view: -// - keep going down on the right until you reach a view with no children, if it -// it is a good candidate return it. -// - start the search on the left sibling. -// - if there are no left sibling, start the search on the parent (without going -// down). -View* FocusSearch::FindPreviousFocusableViewImpl( - View* starting_view, - bool check_starting_view, - bool can_go_up, - bool can_go_down, - int skip_group_id, - FocusTraversable** focus_traversable, - View** focus_traversable_view) const { - // Let's go down and right as much as we can. - if (can_go_down) { - // Before we go into the direct children, we have to check if this view has - // a FocusTraversable. - *focus_traversable = starting_view->GetFocusTraversable(); - if (*focus_traversable) { - *focus_traversable_view = starting_view; - return NULL; - } - - if (!starting_view->children_empty()) { - View* view = starting_view->child_at(starting_view->children_size() - 1); - View* v = FindPreviousFocusableViewImpl(view, true, false, true, - skip_group_id, - focus_traversable, - focus_traversable_view); - if (v || *focus_traversable) - return v; - } - } - - // Then look at this view. Here, we do not need to see if the view has - // a FocusTraversable, since we do not want to go down any more. - if (check_starting_view && - IsViewFocusableCandidate(starting_view, skip_group_id)) { - View* v = FindSelectedViewForGroup(starting_view); - // The selected view might not be focusable (if it is disabled for - // example). - if (IsFocusable(v)) - return v; - } - - // Then try the left sibling. - View* sibling = starting_view->GetPreviousFocusableView(); - if (sibling) { - return FindPreviousFocusableViewImpl(sibling, - true, true, true, - skip_group_id, - focus_traversable, - focus_traversable_view); - } - - // Then go up the parent. - if (can_go_up) { - View* parent = GetParent(starting_view); - if (parent) - return FindPreviousFocusableViewImpl(parent, - true, true, false, - skip_group_id, - focus_traversable, - focus_traversable_view); - } - - // We found nothing. - return NULL; -} - -} // namespace ui diff --git a/ui/views/focus/focus_search.h b/ui/views/focus/focus_search.h deleted file mode 100644 index 3cda790..0000000 --- a/ui/views/focus/focus_search.h +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_FOCUS_FOCUS_SEARCH_H_ -#define UI_VIEWS_FOCUS_FOCUS_SEARCH_H_ -#pragma once - -#include "ui/views/view.h" - -namespace ui { - -class FocusTraversable; - -// FocusSearch is an object that implements the algorithm to find the -// next view to focus. -class FocusSearch { - public: - // The direction in which the focus traversal is going. - // TODO (jcampan): add support for lateral (left, right) focus traversal. The - // goal is to switch to focusable views on the same level when using the arrow - // keys (ala Windows: in a dialog box, arrow keys typically move between the - // dialog OK, Cancel buttons). - enum Direction { - UP = 0, - DOWN - }; - - // Constructor. - // - |root| is the root of the view hierarchy to traverse. Focus will be - // trapped inside. - // - |cycle| should be true if you want FindNextFocusableView to cycle back - // to the first view within this root when the traversal reaches - // the end. If this is true, then if you pass a valid starting - // view to FindNextFocusableView you will always get a valid view - // out, even if it's the same view. - // - |accessibility_mode| should be true if full keyboard accessibility is - // needed and you want to check IsAccessibilityFocusableInRootView(), - // rather than IsFocusableInRootView(). - FocusSearch(View* root, bool cycle, bool accessibility_mode); - virtual ~FocusSearch() {} - - // Finds the next view that should be focused and returns it. If a - // FocusTraversable is found while searching for the focusable view, - // returns NULL and sets |focus_traversable| to the FocusTraversable - // and |focus_traversable_view| to the view associated with the - // FocusTraversable. - // - // Return NULL if the end of the focus loop is reached, unless this object - // was initialized with |cycle|=true, in which case it goes back to the - // beginning when it reaches the end of the traversal. - // - |starting_view| is the view that should be used as the starting point - // when looking for the previous/next view. It may be NULL (in which case - // the first/last view should be used depending if normal/reverse). - // - |reverse| whether we should find the next (reverse is false) or the - // previous (reverse is true) view. - // - |direction| specifies whether we are traversing down (meaning we should - // look into child views) or traversing up (don't look at child views). - // - |check_starting_view| is true if starting_view may obtain the next focus. - // - |focus_traversable| is set to the focus traversable that should be - // traversed if one is found (in which case the call returns NULL). - // - |focus_traversable_view| is set to the view associated with the - // FocusTraversable set in the previous parameter (it is used as the - // starting view when looking for the next focusable view). - virtual View* FindNextFocusableView(View* starting_view, - bool reverse, - Direction direction, - bool check_starting_view, - FocusTraversable** focus_traversable, - View** focus_traversable_view) const; - - private: - // Convenience method that returns true if a view is focusable and does not - // belong to the specified group. - bool IsViewFocusableCandidate(View* v, int skip_group_id) const; - - // Convenience method; returns true if a view is not NULL and is focusable - // (checking IsAccessibilityFocusableInRootView() if accessibility_mode_ is - // true). - bool IsFocusable(View* v) const; - - // Returns the view selected for the group of the selected view. If the view - // does not belong to a group or if no view is selected in the group, the - // specified view is returned. - View* FindSelectedViewForGroup(View* view) const; - - // Get the parent, but stay within the root. Returns NULL if asked for - // the parent of root_. - View* GetParent(View* view) const; - - // Returns the next focusable view or view containing a FocusTraversable - // (NULL if none was found), starting at the starting_view. - // |check_starting_view|, |can_go_up| and |can_go_down| controls the - // traversal of the views hierarchy. |skip_group_id| specifies a group_id, - // -1 means no group. All views from a group are traversed in one pass. - View* FindNextFocusableViewImpl(View* starting_view, - bool check_starting_view, - bool can_go_up, - bool can_go_down, - int skip_group_id, - FocusTraversable** focus_traversable, - View** focus_traversable_view) const; - - // Same as FindNextFocusableViewImpl but returns the previous focusable view. - View* FindPreviousFocusableViewImpl(View* starting_view, - bool check_starting_view, - bool can_go_up, - bool can_go_down, - int skip_group_id, - FocusTraversable** focus_traversable, - View** focus_traversable_view) const; - - View* root_; - bool cycle_; - bool accessibility_mode_; - - DISALLOW_COPY_AND_ASSIGN(FocusSearch); -}; - -} // namespace ui - -#endif // UI_VIEWS_FOCUS_FOCUS_SEARCH_H_ diff --git a/ui/views/layout/fill_layout.cc b/ui/views/layout/fill_layout.cc deleted file mode 100644 index 2c5e588..0000000 --- a/ui/views/layout/fill_layout.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/layout/fill_layout.h" - -#include "base/logging.h" -#include "ui/views/view.h" - -namespace ui { - -//////////////////////////////////////////////////////////////////////////////// -// FillLayout, public: - -FillLayout::FillLayout() { -} - -FillLayout::~FillLayout() { -} - -//////////////////////////////////////////////////////////////////////////////// -// FillLayout, LayoutManager implementation: - -void FillLayout::Layout(View* host) { - if (host->children_empty()) - return; - - View* child = host->child_at(0); - child->SetBounds(gfx::Rect(gfx::Point(), host->size())); -} - -gfx::Size FillLayout::GetPreferredSize(View* host) { - DCHECK_EQ(1U, host->children_size()); - return host->child_at(0)->GetPreferredSize(); -} - -} // namespace ui diff --git a/ui/views/layout/fill_layout.h b/ui/views/layout/fill_layout.h deleted file mode 100644 index 559f2e8..0000000 --- a/ui/views/layout/fill_layout.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_LAYOUT_FILL_LAYOUT_H_ -#define UI_VIEWS_LAYOUT_FILL_LAYOUT_H_ -#pragma once - -#include "base/logging.h" -#include "ui/views/layout/layout_manager.h" - -namespace ui { - -//////////////////////////////////////////////////////////////////////////////// -// FillLayout class -// -// A simple LayoutManager that compels a single view to fit its parent. -// -class FillLayout : public LayoutManager { - public: - FillLayout(); - virtual ~FillLayout(); - - // Overridden from LayoutManager: - virtual void Layout(View* host); - virtual gfx::Size GetPreferredSize(View* host); - - private: - DISALLOW_COPY_AND_ASSIGN(FillLayout); -}; - -} // namespace ui - -#endif // UI_VIEWS_LAYOUT_FILL_LAYOUT_H_ - diff --git a/ui/views/layout/layout_manager.cc b/ui/views/layout/layout_manager.cc deleted file mode 100644 index e3ac839..0000000 --- a/ui/views/layout/layout_manager.cc +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/layout/layout_manager.h" - -#include "ui/views/view.h" - -namespace ui { - -int LayoutManager::GetPreferredHeightForWidth(View* host, int width) { - return GetPreferredSize(host).height(); -} - -} // namespace ui diff --git a/ui/views/layout/layout_manager.h b/ui/views/layout/layout_manager.h deleted file mode 100644 index d985d0d..0000000 --- a/ui/views/layout/layout_manager.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_LAYOUT_LAYOUT_MANAGER_H_ -#define UI_VIEWS_LAYOUT_LAYOUT_MANAGER_H_ -#pragma once - -namespace gfx { -class Size; -} - -namespace ui { - -class View; - -//////////////////////////////////////////////////////////////////////////////// -// LayoutManager interface -// -// An interface implemented by an object that manages sizing of a View's -// children. -// -class LayoutManager { - public: - virtual ~LayoutManager() {} - - // Notification that this LayoutManager has been installed on a particular - // host. - virtual void Installed(View* host) {} - - // Notification that this LayoutManager has been uninstalled on a particular - // host. - virtual void Uninstalled(View* host) {} - - // Lay out the children of |host| according to implementation-specific - // heuristics. The graphics used during painting is provided to allow for - // string sizing. - virtual void Layout(View* host) = 0; - - // Return the preferred size which is the size required to give each - // children their respective preferred size. - virtual gfx::Size GetPreferredSize(View* host) = 0; - - // Returns the preferred height for the specified width. The default - // implementation returns the value from GetPreferredSize. - virtual int GetPreferredHeightForWidth(View* host, int width); - - // Notification that a view has been added. - virtual void ViewAdded(View* host, View* view) {} - - // Notification that a view has been removed. - virtual void ViewRemoved(View* host, View* view) {} -}; - -} // namespace ui - -#endif // UI_VIEWS_LAYOUT_LAYOUT_MANAGER_H_ diff --git a/ui/views/rendering/border.cc b/ui/views/rendering/border.cc deleted file mode 100644 index c4d0200..0000000 --- a/ui/views/rendering/border.cc +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/rendering/border.h" - -#include "ui/gfx/canvas.h" -#include "ui/views/view.h" - -namespace ui { - -namespace internal { - -class SolidColorBorder : public Border { - public: - SolidColorBorder(int thickness, SkColor color) : color_(color) { - set_insets(gfx::Insets(thickness, thickness, thickness, thickness)); - } - virtual ~SolidColorBorder() { - } - - // Overridden from Border: - virtual void Paint(const View* view, gfx::Canvas* canvas) const { - canvas->FillRectInt(color_, 0, 0, view->width(), insets().top()); - canvas->FillRectInt(color_, 0, 0, insets().left(), view->height()); - canvas->FillRectInt(color_, 0, view->height() - insets().bottom(), - view->width(), insets().bottom()); - canvas->FillRectInt(color_, view->width() - insets().right(), 0, - insets().right(), view->height()); - } - - private: - SkColor color_; - - DISALLOW_COPY_AND_ASSIGN(SolidColorBorder); -}; - -} - -//////////////////////////////////////////////////////////////////////////////// -// Border, public: - -Border::~Border() { -} - -// static -Border* Border::CreateSolidBorder(int thickness, SkColor color) { - return new internal::SolidColorBorder(thickness, color); -} - -// static -Border* Border::CreateTransparentBorder(const gfx::Insets& insets) { - Border* b = new Border; - b->set_insets(insets); - return b; -} - -void Border::Paint(const View* view, gfx::Canvas* canvas) const { - // Nothing to do. -} - -//////////////////////////////////////////////////////////////////////////////// -// Border, private: - -Border::Border() { -} - -} // namespace ui - diff --git a/ui/views/rendering/border.h b/ui/views/rendering/border.h deleted file mode 100644 index 6a24411..0000000 --- a/ui/views/rendering/border.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_BORDER_H_ -#define UI_VIEWS_BORDER_H_ - -#include "base/logging.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/gfx/insets.h" - -namespace gfx { -class Canvas; -} - -namespace ui { - -class View; - -//////////////////////////////////////////////////////////////////////////////// -// Border class -// -// A class that provides padding for a View. Subclass to provide custom -// rendering of the Border. Insets determine the size of border. -// -class Border { - public: - virtual ~Border(); - - // Create various common border types. - static Border* CreateSolidBorder(int thickness, SkColor color); - static Border* CreateTransparentBorder(const gfx::Insets& insets); - - gfx::Insets insets() const { return insets_; } - void set_insets(const gfx::Insets& insets) { insets_ = insets; } - - virtual void Paint(const View* view, gfx::Canvas* canvas) const; - - protected: - Border(); - - private: - gfx::Insets insets_; - - DISALLOW_COPY_AND_ASSIGN(Border); -}; - -} // namespace ui - -#endif // UI_VIEWS_BORDER_H_ diff --git a/ui/views/rendering/border_unittest.cc b/ui/views/rendering/border_unittest.cc deleted file mode 100644 index baa585c..0000000 --- a/ui/views/rendering/border_unittest.cc +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <algorithm> - -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/gfx/canvas.h" -#include "ui/views/rendering/border.h" -#include "ui/views/view.h" - -namespace ui { - -class BorderTest : public testing::Test { - public: - BorderTest() {} - virtual ~BorderTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(BorderTest); -}; - -class TestBorder : public Border { - public: - TestBorder() : painted_(false) {} - - bool painted() const { return painted_; } - - // Overridden from Border: - virtual void Paint(const View* view, gfx::Canvas* canvas) const { - painted_ = true; - } - - private: - mutable bool painted_; - - DISALLOW_COPY_AND_ASSIGN(TestBorder); -}; - -class PaintableView : public View { - public: - PaintableView() {} - virtual ~PaintableView() {} - - void CallOnPaintWithNULLCanvas() { - OnPaint(NULL); - } - - private: - DISALLOW_COPY_AND_ASSIGN(PaintableView); -}; - -TEST_F(BorderTest, Basic) { - const int kViewSize = 100; - PaintableView v; - v.SetBounds(gfx::Rect(10, 10, kViewSize, kViewSize)); - - // With no border, the content size is the view size. - EXPECT_EQ(gfx::Rect(0, 0, kViewSize, kViewSize), v.GetContentsBounds()); - - const int kViewInset = 10; - v.SetBorder(Border::CreateTransparentBorder( - gfx::Insets(kViewInset, kViewInset, kViewInset, kViewInset))); - - // With the border, the content bounds are inset by the border's insets. - EXPECT_EQ(gfx::Rect(kViewInset, kViewInset, kViewSize - 2 * kViewInset, - kViewSize - 2 * kViewInset), - v.GetContentsBounds()); - - TestBorder* border = new TestBorder; - v.SetBorder(border); - v.CallOnPaintWithNULLCanvas(); - EXPECT_TRUE(border->painted()); -} - -} // namespace ui diff --git a/ui/views/view.cc b/ui/views/view.cc deleted file mode 100644 index 14a797b..0000000 --- a/ui/views/view.cc +++ /dev/null @@ -1,664 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/view.h" - -#include <algorithm> -#include <functional> - -#include "ui/base/dragdrop/drag_drop_types.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/point.h" -#include "ui/gfx/size.h" -#include "ui/views/events/context_menu_controller.h" -#include "ui/views/events/drag_controller.h" -#include "ui/views/layout/layout_manager.h" -#include "ui/views/rendering/border.h" -#include "ui/views/widget/widget.h" - -namespace ui { - -namespace { - -// Saves gfx::Canvas state upon construction and automatically restores it when -// it goes out of scope. -class ScopedCanvasState { - public: - explicit ScopedCanvasState(gfx::Canvas* canvas) : canvas_(canvas) { - canvas_->Save(); - } - ~ScopedCanvasState() { - canvas_->Restore(); - } - - private: - gfx::Canvas* canvas_; - DISALLOW_COPY_AND_ASSIGN(ScopedCanvasState); -}; - -bool ExceededDragThreshold(const gfx::Point& press_point, - const gfx::Point& event_point) { - // TODO(beng): implement - return true; -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// View, public: - -View::View() - : parent_owned_(true), - visible_(true), - enabled_(true), - id_(-1), - group_(-1), - parent_(NULL), - focusable_(false), - next_focusable_view_(NULL), - prev_focusable_view_(NULL), - context_menu_controller_(NULL), - drag_controller_(NULL) { -} - -View::~View() { - if (parent_) - parent_->RemoveChildView(this, false); - - for (Views::const_iterator i(children_begin()); i != children_.end(); ++i) { - (*i)->parent_ = NULL; - if ((*i)->parent_owned()) - delete *i; - } -} - -// Size and disposition -------------------------------------------------------- - -gfx::Rect View::GetVisibleBounds() const { - // TODO(beng): - return bounds(); -} - -gfx::Rect View::GetContentsBounds() const { - gfx::Rect rect(gfx::Point(), size()); - if (border_.get()) - rect.Inset(border_->insets()); - return rect; -} - -void View::SetBounds(const gfx::Rect& bounds) { - gfx::Rect old_bounds = bounds_; - bounds_ = bounds; - // TODO(beng): investigate usage of needs_layout_ in old View code. - if (old_bounds != bounds_) { - OnBoundsChanged(); - Layout(); - } -} - -void View::SetOrigin(const gfx::Point& origin) { - SetBounds(gfx::Rect(origin, size())); -} - -void View::SetSize(const gfx::Size& size) { - SetBounds(gfx::Rect(origin(), size)); -} - -void View::SetBorder(Border* border) { - border_.reset(border); -} - -void View::OnBoundsChanged() { -} - -gfx::Size View::GetPreferredSize() const { - return gfx::Size(); -} - -gfx::Size View::GetMinimumSize() const { - return GetPreferredSize(); -} - -void View::SetLayoutManager(LayoutManager* layout_manager) { - layout_manager_.reset(layout_manager); -} - -void View::Layout() { - // The layout manager handles all child layout if present. - if (layout_manager_.get()) { - layout_manager_->Layout(this); - } else { - std::for_each(children_begin(), children_end(), - std::mem_fun(&View::Layout)); - } - // TODO(beng): needs_layout_? SchedulePaint()? -} - -void View::SetVisible(bool visible) { - if (visible != visible_) { - visible_ = visible; - // InvaldateRect() checks for view visibility before proceeding, so we need - // to ask the parent to invalidate our bounds. - if (parent_) - parent_->InvalidateRect(bounds_); - } -} - -void View::SetEnabled(bool enabled) { - if (enabled != enabled_) { - enabled_ = enabled; - Invalidate(); - } -} - -// Attributes ------------------------------------------------------------------ - -View* View::GetViewByID(int id) { - if (id_ == id) - return this; - for (Views::const_iterator i(children_begin()); i != children_end(); ++i) { - View* view = (*i)->GetViewByID(id); - if (view) - return view; - } - return NULL; -} - -void View::GetViewsInGroup(int group, Views* vec) { - if (group_ == group) - vec->push_back(const_cast<View*>(this)); - for (Views::const_iterator i(children_begin()); i != children_end(); ++i) - (*i)->GetViewsInGroup(group, vec); -} - -View* View::GetSelectedViewForGroup(int group_id) { - // TODO(beng): implementme - return NULL; -} - -// Coordinate conversion ------------------------------------------------------- - -// static -void View::ConvertPointToView(const View& source, - const View& target, - gfx::Point* point) { - const View* inner = NULL; - const View* outer = NULL; - if (source.Contains(target)) { - inner = ⌖ - outer = &source; - } else if (target.Contains(source)) { - inner = &source; - outer = ⌖ - } // Note that we cannot do a plain "else" here since |source| and |target| - // may be in different hierarchies with no relation. - if (!inner) - return; - - gfx::Point offset; - for (const View* v = inner; v != outer; v = v->parent()) - offset.Offset(v->x(), v->y()); - // When target is contained by source, we need to subtract the offset. - // When source is contained by target, we need to add the offset. - int multiplier = (inner == &target) ? -1 : 1; - point->Offset(multiplier * offset.x(), multiplier * offset.y()); -} - -// static -void View::ConvertPointToScreen(const View& source, gfx::Point* point) { - const Widget* widget = source.GetWidget(); - if (widget) { - ConvertPointToWidget(source, point); - gfx::Point client_origin(widget->GetClientAreaScreenBounds().origin()); - point->Offset(client_origin.x(), client_origin.y()); - } -} - -// static -void View::ConvertPointToWidget(const View& source, gfx::Point* point) { - for (const View* v = &source; v; v = v->parent()) - point->Offset(v->x(), v->y()); -} - -// Tree operations ------------------------------------------------------------- - -const Widget* View::GetWidget() const { - return parent() ? parent()->GetWidget() : NULL; -} - -void View::AddChildView(View* view) { - AddChildViewAt(view, children_size()); -} - -void View::AddChildViewAt(View* view, size_t index) { - CHECK_NE(this, view) << "A view cannot be its own child."; - - // Remove the child from its current parent if any. - if (view->parent()) - view->parent()->RemoveChildView(view, false); - - // TODO(beng): Move focus initialization to FocusManager. - InitFocusSiblings(view, index); - - children_.insert(children_.begin() + index, view); - view->parent_ = this; - - // Notify the hierarchy. - NotifyHierarchyChanged(view, true); - - // TODO(beng): Notify other objects like tooltip, layout manager, etc. - // Figure out RegisterChildrenForVisibleBoundsNotification. -} - -void View::RemoveChildView(View* view, bool delete_child) { - Views::const_iterator i(std::find(children_begin(), children_end(), view)); - DCHECK(i != children_end()); - view->parent_ = NULL; - children_.erase(i); - NotifyHierarchyChanged(view, false); - // TODO(beng): Notify other objects like tooltip, layout manager, etc. - if (delete_child) - delete view; -} - -void View::RemoveAllChildViews(bool delete_children) { - while (!children_.empty()) { - RemoveChildView(children_.front(), delete_children); - // TODO(beng): view deletion is actually more complicated in the old view.cc - // figure out why. (it uses a ScopedVector to accumulate a list - // of views to delete). - } -} - -bool View::Contains(const View& child) const { - for (const View* v = &child; v; v = v->parent()) { - if (v == this) - return true; - } - return false; -} - -// Painting -------------------------------------------------------------------- - -void View::Invalidate() { - InvalidateRect(gfx::Rect(gfx::Point(), size())); -} - -void View::InvalidateRect(const gfx::Rect& invalid_rect) { - if (visible_ && parent_) { - gfx::Rect r(invalid_rect); - r.Offset(bounds_.origin()); - parent_->InvalidateRect(r); - } -} - -// Input ----------------------------------------------------------------------- - -bool View::HitTest(const gfx::Point& point) const { - // TODO(beng): Hit test mask support. - return gfx::Rect(gfx::Point(), size()).Contains(point); -} - -// Accelerators ---------------------------------------------------------------- - -void View::AddAccelerator(const Accelerator& accelerator) { -} - -void View::RemoveAccelerator(const Accelerator& accelerator) { -} - -void View::RemoveAllAccelerators() { -} - -// Focus ----------------------------------------------------------------------- - -FocusManager* View::GetFocusManager() { - return const_cast<FocusManager*>(static_cast<const View*>(this)-> - GetFocusManager()); -} - -const FocusManager* View::GetFocusManager() const { - const Widget* widget = GetWidget(); - return widget ? widget->GetFocusManager() : NULL; -} - -FocusTraversable* View::GetFocusTraversable() { - return NULL; -} - -View* View::GetNextFocusableView() { - return NULL; -} - -View* View::GetPreviousFocusableView() { - return NULL; -} - -bool View::IsFocusable() const { - return focusable_ && enabled_ && visible_; -} - -bool View::HasFocus() const { - const FocusManager* focus_manager = GetFocusManager(); - return focus_manager ? (focus_manager->focused_view() == this) : false; -} - -void View::RequestFocus() { - FocusManager* focus_manager = GetFocusManager(); - if (focus_manager && (focus_manager->focused_view() != this)) - focus_manager->SetFocusedView(this); -} - -// Resources ------------------------------------------------------------------- - -ThemeProvider* View::GetThemeProvider() { - Widget* widget = GetWidget(); - return widget ? widget->GetThemeProvider() : NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// View, protected: - -// Tree operations ------------------------------------------------------------- - -void View::OnViewAdded(const View& parent, const View& child) { -} - -void View::OnViewRemoved(const View& parent, const View& child) { -} - -void View::OnViewAddedToWidget() { -} - -void View::OnViewRemovedFromWidget() { -} - -// Painting -------------------------------------------------------------------- - -void View::PaintChildren(gfx::Canvas* canvas) { - std::for_each(children_begin(), children_end(), - std::bind2nd(std::mem_fun(&View::Paint), canvas)); -} - -void View::OnPaint(gfx::Canvas* canvas) { - // TODO(beng): investigate moving these function calls to Paint(). - OnPaintBackground(canvas); - OnPaintFocusBorder(canvas); - OnPaintBorder(canvas); -} - -void View::OnPaintBackground(gfx::Canvas* canvas) { -} - -void View::OnPaintBorder(gfx::Canvas* canvas) { - if (border_.get()) - border_->Paint(this, canvas); -} - -void View::OnPaintFocusBorder(gfx::Canvas* canvas) { -} - -// Input ----------------------------------------------------------------------- - -View* View::GetEventHandlerForPoint(const gfx::Point& point) { - for (Views::const_reverse_iterator i(children_rbegin()); i != children_rend(); - ++i) { - View* child = *i; - if (child->visible()) { - gfx::Point point_in_child_coords(point); - View::ConvertPointToView(*this, *child, &point_in_child_coords); - if (child->HitTest(point_in_child_coords)) - return child->GetEventHandlerForPoint(point_in_child_coords); - } - } - return this; -} - -gfx::NativeCursor View::GetCursorForPoint(const gfx::Point& point) const { - return gfx::kNullCursor; -} - -bool View::OnKeyPressed(const KeyEvent& event) { - return true; -} - -bool View::OnKeyReleased(const KeyEvent& event) { - return true; -} - -bool View::OnMouseWheel(const MouseWheelEvent& event) { - return true; -} - -bool View::OnMousePressed(const MouseEvent& event) { - return true; -} - -bool View::OnMouseDragged(const MouseEvent& event) { - return true; -} - -void View::OnMouseReleased(const MouseEvent& event) { -} - -void View::OnMouseCaptureLost() { -} - -void View::OnMouseMoved(const MouseEvent& event) { -} - -void View::OnMouseEntered(const MouseEvent& event) { -} - -void View::OnMouseExited(const MouseEvent& event) { -} - -// Accelerators ---------------------------------------------------------------- - -bool View::OnAcceleratorPressed(const Accelerator& accelerator) { - return false; -} - -// Focus ----------------------------------------------------------------------- - -bool View::SkipDefaultKeyEventProcessing(const KeyEvent& event) const { - return false; -} - -bool View::IsGroupFocusTraversable() const { - return true; -} - -bool View::IsFocusableInRootView() const { - // TODO(beng): kill this, replace with direct check in focus manager. - return IsFocusable(); -} - -bool View::IsAccessibilityFocusableInRootView() const { - // TODO(beng): kill this, replace with direct check in focus manager. - return false; -} - -FocusTraversable* View::GetPaneFocusTraversable() { - // TODO(beng): figure out what to do about this. - return NULL; -} - -void View::OnFocus(const FocusEvent& event) { -} - -void View::OnBlur(const FocusEvent& event) { -} - -//////////////////////////////////////////////////////////////////////////////// -// View, private: - -void View::DragInfo::Reset() { - possible_drag = false; - press_point = gfx::Point(); -} - -void View::DragInfo::PossibleDrag(const gfx::Point& point) { - possible_drag = true; - press_point = point; -} - -// Tree operations ------------------------------------------------------------- - -void View::NotifyHierarchyChanged(View* child, bool is_add) { - // Notify the hierarchy up. - for (View* v = parent(); v; v = v->parent()) - CallViewNotification(v, *child, is_add, false); - - // Notify the hierarchy down. - bool has_widget = GetWidget() != NULL; - if (!is_add) { - // Because |child| has already been removed from |parent|'s child list, we - // need to notify its hierarchy manually. - child->NotifyHierarchyChangedDown(*child, is_add, has_widget); - } - NotifyHierarchyChangedDown(*child, is_add, has_widget); -} - -void View::NotifyHierarchyChangedDown(const View& child, - bool is_add, - bool has_widget) { - CallViewNotification(this, child, is_add, has_widget); - for (Views::const_iterator i(children_begin()); i != children_end(); ++i) - (*i)->NotifyHierarchyChangedDown(child, is_add, has_widget); -} - -void View::CallViewNotification(View* target, - const View& child, - bool is_add, - bool has_widget) { - if (is_add) { - target->OnViewAdded(*this, child); - if (has_widget) - target->OnViewAddedToWidget(); - } else { - target->OnViewRemoved(*this, child); - if (has_widget) - target->OnViewRemovedFromWidget(); - } -} - -// Painting -------------------------------------------------------------------- - -void View::Paint(gfx::Canvas* canvas) { - // Invisible views are not painted. - if (!visible_) - return; - - ScopedCanvasState canvas_state(canvas); - if (canvas->ClipRectInt(bounds_)) { - canvas->TranslateInt(x(), y()); - // TODO(beng): RTL - ScopedCanvasState canvas_state(canvas); - OnPaint(canvas); - PaintChildren(canvas); - } -} - -// Input ----------------------------------------------------------------------- - -bool View::MousePressed(const MouseEvent& event, DragInfo* drag_info) { - bool handled = OnMousePressed(event); - // TODO(beng): deal with view deletion, see ProcessMousePressed() in old code. - if (!enabled_) - return handled; - - if (!event.IsOnlyLeftMouseButton() || !HitTest(event.location()) || - (GetDragOperations(event.location()) == DragDropTypes::DRAG_NONE)) - return handled || (event.IsRightMouseButton() && context_menu_controller_); - - drag_info->PossibleDrag(event.location()); - return true; -} - -bool View::MouseDragged(const MouseEvent& event, DragInfo* drag_info) { - if (drag_info->possible_drag && - ExceededDragThreshold(drag_info->press_point, event.location())) { - if (!drag_controller_ || - drag_controller_->CanStartDrag(this, drag_info->press_point, - event.location())) - StartShellDrag(event, drag_info->press_point); - } else if (OnMouseDragged(event)) { - return true; - } - // TODO(beng): Handle view deletion from OnMouseDragged(). - return context_menu_controller_ || drag_info->possible_drag; -} - -void View::MouseReleased(const MouseEvent& event) { - OnMouseReleased(event); - // TODO(beng): Handle view deletion from OnMouseReleased(). - if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { - gfx::Point location(event.location()); - if (HitTest(location)) { - ConvertPointToScreen(*this, &location); - context_menu_controller_->ShowContextMenu(this, location, true); - } - } -} - -// Focus ----------------------------------------------------------------------- - -// TODO(beng): Move to FocusManager. -void View::InitFocusSiblings(View* view, size_t index) { - if (children_empty()) { - view->next_focusable_view_ = NULL; - view->prev_focusable_view_ = NULL; - return; - } - - if (index != children_size()) { - View* prev = children_[index]->GetPreviousFocusableView(); - view->prev_focusable_view_ = prev; - view->next_focusable_view_ = children_[index]; - if (prev) - prev->next_focusable_view_ = view; - children_[index]->prev_focusable_view_ = view; - return; - } - - // We are inserting at the end, but the end of the child list may not be - // the last focusable element. Let's try to find an element with no next - // focusable element to link to. - for (Views::const_iterator i(children_begin()); i != children_end(); ++i) { - if (!(*i)->next_focusable_view_) { - (*i)->next_focusable_view_ = view; - view->next_focusable_view_ = NULL; - view->prev_focusable_view_ = *i; - return; - } - } - - // Hum... there is a cycle in the focus list. Let's just insert ourself - // after the last child. - View* prev = children_[index - 1]; - view->prev_focusable_view_ = prev; - view->next_focusable_view_ = prev->next_focusable_view_; - prev->next_focusable_view_->prev_focusable_view_ = view; - prev->next_focusable_view_ = view; -} - -// Drag & Drop ----------------------------------------------------------------- - -int View::GetDragOperations(const gfx::Point& point) { - return drag_controller_ ? - drag_controller_->GetDragOperations(this, point) : - DragDropTypes::DRAG_NONE; -} - -void View::WriteDragData(const gfx::Point& point, OSExchangeData* data) { - drag_controller_->WriteDragData(this, point, data); -} - -void View::StartShellDrag(const MouseEvent& event, - const gfx::Point& press_point) { - // TODO(beng): system stuff. -} - -} // namespace ui diff --git a/ui/views/view.h b/ui/views/view.h deleted file mode 100644 index ffcbbb4..0000000 --- a/ui/views/view.h +++ /dev/null @@ -1,476 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_VIEW_H_ -#define UI_VIEWS_VIEW_H_ - -#include <vector> - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/rect.h" - -namespace gfx { -class Canvas; -class Point; -class Rect; -class Size; -} - -namespace ui { -namespace internal { -class RootView; -} -class Accelerator; -class Border; -class ContextMenuController; -class DragController; -class FocusEvent; -class FocusManager; -class FocusTraversable; -class KeyEvent; -class LayoutManager; -class MouseEvent; -class MouseWheelEvent; -class OSExchangeData; -class ThemeProvider; -class Widget; - -//////////////////////////////////////////////////////////////////////////////// -// View -// -// View encapsulates rendering, layout and event handling for rectangles within -// a view hierarchy. -// -// Client code typically subclasses View and overrides virtual methods to -// handle painting, child view positioning and handle certain types of events. -// -// Views are owned by their parent View unless specified otherwise. This means -// that in most cases Views are automatically destroyed when the window that -// contains them is destroyed. -// -// TODO(beng): consider the visibility of many of these methods. -// consider making RootView a friend and making many private or -// protected. - -class View { - public: - typedef std::vector<View*> Views; - - // Creation and lifetime ----------------------------------------------------- - View(); - virtual ~View(); - - // By default a View is owned by its parent unless specified otherwise here. - bool parent_owned() const { return parent_owned_; } - void set_parent_owned(bool parent_owned) { parent_owned_ = parent_owned; } - - void set_drag_controller(DragController* drag_controller) { - drag_controller_ = drag_controller; - } - - // Size and disposition ------------------------------------------------------ - - gfx::Rect bounds() const { return bounds_; } - // Returns the portion of this view's bounds that are visible (i.e. not - // clipped) in the RootView. - gfx::Rect GetVisibleBounds() const; - // Returns the bounds of the content area of the view, i.e. the rectangle - // enclosed by the view's border. - gfx::Rect GetContentsBounds() const; - void SetBounds(const gfx::Rect& bounds); - - gfx::Point origin() const { return bounds().origin(); } - int x() const { return bounds().x(); } - int y() const { return bounds().y(); } - void SetOrigin(const gfx::Point& origin); - - gfx::Size size() const { return bounds().size(); } - int width() const { return bounds().width(); } - int height() const { return bounds().height(); } - void SetSize(const gfx::Size& size); - - // Owned by the view. - Border* border() { return border_.get(); } - void SetBorder(Border* border); - - // Override to be notified when the bounds of a view have changed. - virtual void OnBoundsChanged(); - - virtual gfx::Size GetPreferredSize() const; - virtual gfx::Size GetMinimumSize() const; - - void SetLayoutManager(LayoutManager* layout_manager); - virtual void Layout(); - - // If a View is not visible, it will not be rendered, focused, etc. - bool visible() const { return visible_; } - void SetVisible(bool visible); - - // Disabled Views will not receive mouse press/release events, nor can they be - // focused. - bool enabled() const { return enabled_; } - void SetEnabled(bool enabled); - - // Attributes ---------------------------------------------------------------- - - int id() const { return id_; } - void set_id(int id) { id_ = id; } - int group() const { return group_; } - void set_group(int group) { group_ = group; } - - // Returns the View within this View's hierarchy whose id matches that - // specified. - View* GetViewByID(int id); - - // Populates |vec| with the Views within this View's hierarchy that match the - // specified group id. - void GetViewsInGroup(int group, Views* vec); - - // TODO(beng): implementme - virtual View* GetSelectedViewForGroup(int group_id); - - // Coordinate conversion ----------------------------------------------------- - - // Converts a point from the coordinate system of |source| to |target|. - static void ConvertPointToView(const View& source, - const View& target, - gfx::Point* point); - - // Converts a point from the coordinate system of |source| to the screen. - // If |source| is not attached to a Widget that is in screen space, |point| is - // not modified. - static void ConvertPointToScreen(const View& source, gfx::Point* point); - - // Converts a point from the coordinate system of |source| to the Widget that - // most closely contains it. - static void ConvertPointToWidget(const View& source, gfx::Point* point); - - // Tree operations ----------------------------------------------------------- - - // Returns the Widget that contains this View, or NULL if it is not contained - // within a Widget. - Widget* GetWidget() { - return const_cast<Widget*>(static_cast<const View*>(this)->GetWidget()); - } - virtual const Widget* GetWidget() const; - - // Adds a View as a child of this one, optionally at |index|. - void AddChildView(View* view); - void AddChildViewAt(View* view, size_t index); - - // If |view| is a child of this View, removes it and optionally deletes it. - void RemoveChildView(View* view, bool delete_child); - - // Removes all View children of this View. Deletes the children if - // |delete_children| is true. - void RemoveAllChildViews(bool delete_children); - - // STL-style accessors. - Views::const_iterator children_begin() { return children_.begin(); } - Views::const_iterator children_end() { return children_.end(); } - Views::const_reverse_iterator children_rbegin() { return children_.rbegin(); } - Views::const_reverse_iterator children_rend() { return children_.rend(); } - size_t children_size() const { return children_.size(); } - bool children_empty() const { return children_.empty(); } - View* child_at(size_t index) { - DCHECK_LT(index, children_size()); - return children_[index]; - } - - // Returns the parent View, or NULL if this View has no parent. - View* parent() { return parent_; } - const View* parent() const { return parent_; } - - // Returns true if |child| is contained within this View's hierarchy, even as - // an indirect descendant. Will return true if child is also this View. - bool Contains(const View& child) const; - - // Painting ------------------------------------------------------------------ - - // Add all or part of a View's bounds to the enclosing Widget's invalid - // rectangle. This will result in those areas being re-painted on the next - // update. - void Invalidate(); - virtual void InvalidateRect(const gfx::Rect& invalid_rect); - - // Input --------------------------------------------------------------------- - - // Returns true if the specified point is contained within this View or its - // hit test mask. |point| is in this View's coordinates. - bool HitTest(const gfx::Point& point) const; - - // Accelerators -------------------------------------------------------------- - - // Accelerator Registration. - void AddAccelerator(const Accelerator& accelerator); - void RemoveAccelerator(const Accelerator& accelerator); - void RemoveAllAccelerators(); - - // Focus --------------------------------------------------------------------- - - // Manager. - FocusManager* GetFocusManager(); - const FocusManager* GetFocusManager() const; - - // Traversal. - virtual FocusTraversable* GetFocusTraversable(); - View* GetNextFocusableView(); - View* GetPreviousFocusableView(); - - // Attributes. - bool IsFocusable() const; - void set_focusable(bool focusable) { focusable_ = focusable; } - - bool HasFocus() const; - void RequestFocus(); - - // Context menus ------------------------------------------------------------- - - void set_context_menu_controller( - ContextMenuController* context_menu_controller) { - context_menu_controller_ = context_menu_controller; - } - - // Resources ----------------------------------------------------------------- - - ThemeProvider* GetThemeProvider(); - - protected: - // Tree operations ----------------------------------------------------------- - - // Called on every view in |parent|'s and |child|'s hierarchies, as well as - // ancestors, when |child| is added to or removed from |parent|. - virtual void OnViewAdded(const View& parent, const View& child); - virtual void OnViewRemoved(const View& parent, const View& child); - - // Called on a View when it is part of a hierarchy that has been added to or - // removed from a Widget. - virtual void OnViewAddedToWidget(); - virtual void OnViewRemovedFromWidget(); - - // Painting ------------------------------------------------------------------ - - // Responsible for calling Paint() on child Views. Override to control the - // order child Views are painted. - virtual void PaintChildren(gfx::Canvas* canvas); - - // Override to provide rendering in any part of the View's bounds. Typically - // this is the "contents" of the view. If you override this method you will - // have to call the subsequent OnPaint*() methods manually. - virtual void OnPaint(gfx::Canvas* canvas); - - // Override to paint a background before any content is drawn. Typically this - // is done if you are satisfied with a default OnPaint handler but wish to - // supply a different background. - virtual void OnPaintBackground(gfx::Canvas* canvas); - - // Override to paint a border not specified by SetBorder(). - virtual void OnPaintBorder(gfx::Canvas* canvas); - - // Override to paint a focus border (usually a dotted rectangle) around - // relevant contents. - virtual void OnPaintFocusBorder(gfx::Canvas* canvas); - - // Input --------------------------------------------------------------------- - - // Returns the visible View that would like to handle events occurring at the - // specified |point|, in this View's coordinates. - // This function is used by the event processing system in the Widget to - // locate views for event targeting. Override this function if you wish to - // specify a view other than the one most closely enclosing |point| to receive - // notifications for events within it. - virtual View* GetEventHandlerForPoint(const gfx::Point& point); - - virtual gfx::NativeCursor GetCursorForPoint(const gfx::Point& point) const; - - virtual bool OnKeyPressed(const KeyEvent& event); - virtual bool OnKeyReleased(const KeyEvent& event); - virtual bool OnMouseWheel(const MouseWheelEvent& event); - // To receive OnMouseDragged() or OnMouseReleased() events, overriding classes - // must return true from this function. - virtual bool OnMousePressed(const MouseEvent& event); - virtual bool OnMouseDragged(const MouseEvent& event); - virtual void OnMouseReleased(const MouseEvent& event); - virtual void OnMouseCaptureLost(); - virtual void OnMouseMoved(const MouseEvent& event); - virtual void OnMouseEntered(const MouseEvent& event); - virtual void OnMouseExited(const MouseEvent& event); - - // Accelerators -------------------------------------------------------------- - - virtual bool OnAcceleratorPressed(const Accelerator& accelerator); - - // Focus --------------------------------------------------------------------- - - virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event) const; - virtual bool IsGroupFocusTraversable() const; - // TODO(beng): kill these, move to focus manager. - virtual bool IsFocusableInRootView() const; - virtual bool IsAccessibilityFocusableInRootView() const; - virtual FocusTraversable* GetPaneFocusTraversable(); - - virtual void OnFocus(const FocusEvent& event); - virtual void OnBlur(const FocusEvent& event); - - private: - friend internal::RootView; - friend class FocusManager; - friend class FocusSearch; - - // State collected during a MousePressed event to detect possible drag - // operations. - struct DragInfo { - // Sets possible_drag to false and start_x/y to 0. This is invoked by - // RootView prior to invoke MousePressed(). - void Reset(); - - // Sets possible_drag to true and start_pt to the specified point. - // This is invoked by the target view if it detects the press may generate - // a drag. - void PossibleDrag(const gfx::Point& point); - - // Whether the press may generate a drag. - bool possible_drag; - - // Position of the mouse press in screen coordinates. - gfx::Point press_point; - }; - - // Tree operations ----------------------------------------------------------- - - // Notifies all views in our and |child|'s hierarchies, as well as ancestors, - // that |child| was added to or removed from |this|. - void NotifyHierarchyChanged(View* child, bool is_add); - - // Notifies all views in our hierarchy that |child| was added to or removed - // from |this|. |has_widget| is true iff |this| is in a widget. - void NotifyHierarchyChangedDown(const View& child, - bool is_add, - bool has_widget); - - // Notifies |target| that |child| was added to or removed from |this|. - // |has_widget| is true iff |this| is in a widget. - void CallViewNotification(View* target, - const View& child, - bool is_add, - bool has_widget); - - // Painting ------------------------------------------------------------------ - - // Called by the framework to paint a View. Performs translation and clipping - // for View coordinates and language direction as required, allows the View - // to paint itself via the various OnPaint*() event handlers and then paints - // the hierarchy beneath it. - void Paint(gfx::Canvas* canvas); - - // Input --------------------------------------------------------------------- - - // These methods are designed to be called by the RootView. The RootView - // should limit its interaction with the View to these methods and the public - // API. - bool MousePressed(const MouseEvent& event, DragInfo* drag_info); - bool MouseDragged(const MouseEvent& event, DragInfo* drag_info); - void MouseReleased(const MouseEvent& event); - - // Focus --------------------------------------------------------------------- - - // Called when |child| is inserted into this View's children_ at |index|. - // Sets up next/previous focus views - // TODO(beng): Move this to FocusManager. - void InitFocusSiblings(View* child, size_t index); - - // Drag & Drop --------------------------------------------------------------- - - int GetDragOperations(const gfx::Point& point); - void WriteDragData(const gfx::Point& point, OSExchangeData* data); - void StartShellDrag(const MouseEvent& event, const gfx::Point& press_point); - - ////////////////////////////////////////////////////////////////////////////// - - // Creation and lifetime ----------------------------------------------------- - - // True if the hierarchy (i.e. the parent View) is responsible for deleting - // this View. Default is true. - bool parent_owned_; - - // Size and disposition ------------------------------------------------------ - - // The bounds of the View, in its parent's coordinates. - gfx::Rect bounds_; - - scoped_ptr<Border> border_; - - // Whether or not this View is visible. The view still participates in layout - // but will not be painted. - bool visible_; - - // Whether or not this View is enabled. When disabled, the event system will - // not propagate un-handled events beyond the View in the hierarchy. - bool enabled_; - - // An optional helper that handles layout for child views. - scoped_ptr<LayoutManager> layout_manager_; - - // Attributes ---------------------------------------------------------------- - - // An identifier for this View. Caller must guarantee uniqueness. - int id_; - - // An identifier for a group of potentially related Views. - int group_; - - // Tree operations ----------------------------------------------------------- - - // The View's parent view. This is set and reset when the View is added and - // removed from a hierarchy. - View* parent_; - - // The View's children. - Views children_; - - // Focus --------------------------------------------------------------------- - - // True if this View is focusable by the FocusManager. - bool focusable_; - - // Focus siblings for this View. - View* next_focusable_view_; - View* prev_focusable_view_; - - // Context menus ------------------------------------------------------------- - - // Shows the context menu. - ContextMenuController* context_menu_controller_; - - // Drag & drop --------------------------------------------------------------- - - // Delegate for drag and drop related functionality. - DragController* drag_controller_; - - DISALLOW_COPY_AND_ASSIGN(View); -}; - -} // namespace ui - -#endif // UI_VIEWS_VIEW_H_ - -/* - -TODO(beng): -- accessibility -- scrolling -- cursors -- tooltips -- rtl -- l10n -- mousewheel -- more on painting -- layer stuff -- investigate why assorted notifications are necessary -- native_widget_views -- native_widget_gtk - -*/ diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc deleted file mode 100644 index ebdc717..0000000 --- a/ui/views/view_unittest.cc +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <algorithm> - -#include "base/compiler_specific.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/gfx/canvas.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace ui { - -class ViewTest : public testing::Test { - public: - ViewTest() {} - virtual ~ViewTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(ViewTest); -}; - -TEST_F(ViewTest, SizeAndDisposition) { - View v; - EXPECT_TRUE(v.bounds().IsEmpty()); - EXPECT_TRUE(v.visible()); - - v.SetBounds(gfx::Rect(10, 10, 200, 200)); - EXPECT_EQ(200, v.width()); - - EXPECT_TRUE(v.GetPreferredSize().IsEmpty()); -} - -TEST_F(ViewTest, TreeOperations) { - View v; - EXPECT_EQ(NULL, v.GetWidget()); - EXPECT_TRUE(v.children_empty()); - - View child1; - v.AddChildView(&child1); - EXPECT_EQ(1, v.children_size()); - EXPECT_EQ(&v, child1.parent()); - - View child2; - v.AddChildViewAt(&child2, 0); - EXPECT_EQ(2, v.children_size()); - EXPECT_EQ(child1.parent(), child2.parent()); - - v.RemoveChildView(&child2, false); - EXPECT_EQ(1, v.children_size()); - EXPECT_EQ(NULL, child2.parent()); - - //v.RemoveAllChildViews(false); - //EXPECT_TRUE(v.children_empty()); -} - -class ObserverView : public View { - public: - ObserverView() - : view_added_(false), - view_removed_(false), - subject_view_(NULL) {} - virtual ~ObserverView() {} - - void ResetTestState() { - view_added_ = false; - view_removed_ = false; - subject_view_ = NULL; - } - - // Overridden from View: - virtual void OnViewAdded(const View& parent, const View& child) OVERRIDE { - view_added_ = true; - view_removed_ = false; - subject_view_ = &child; - } - virtual void OnViewRemoved(const View& parent, const View& child) OVERRIDE { - view_added_ = false; - view_removed_ = true; - subject_view_ = &child; - } - - bool view_added() const { return view_added_; } - bool view_removed() const { return view_removed_; } - View* subject_view() const { return subject_view_; } - - private: - bool view_added_; - bool view_removed_; - View* subject_view_; - - DISALLOW_COPY_AND_ASSIGN(ObserverView); -}; - -class WidgetObserverView : public View { - public: - WidgetObserverView() : in_widget_(false) {} - virtual ~WidgetObserverView() {} - - // Overridden from View: - virtual void OnViewAddedToWidget() { - in_widget_ = true; - } - virtual void OnViewRemovedFromWidget() { - in_widget_ = false; - } - - bool in_widget() const { return in_widget_; } - - private: - bool in_widget_; - - DISALLOW_COPY_AND_ASSIGN(WidgetObserverView); -}; - -/* -TEST_F(ViewTest, HierarchyObserver) { - ObserverView ov; - Widget widget(&ov); - widget.InitWithNativeViewParent(NULL, gfx::Rect(20, 20, 400, 400)); - - // |ov|'s addition to the RootView's hierarchy should have caused these values - // to be set. - EXPECT_TRUE(ov.view_added()); - EXPECT_FALSE(ov.view_removed()); - EXPECT_EQ(&ov, ov.subject_view()); - - ov.ResetTestState(); - - // Direct descendants. - View v2; - ov.AddChildView(&v2); - EXPECT_TRUE(ov.view_added()); - EXPECT_FALSE(ov.view_removed()); - EXPECT_EQ(&v2, ov.subject_view()); - - ov.ResetTestState(); - - // Nested Views and Widget addition. - WidgetObserverView v3; - EXPECT_FALSE(v3.in_widget()); - v2.AddChildView(&v3); - EXPECT_TRUE(v3.in_widget()); - EXPECT_EQ(&widget, v3.GetWidget()); - EXPECT_TRUE(ov.view_added()); - EXPECT_FALSE(ov.view_removed()); - EXPECT_EQ(&v3, ov.subject_view()); - - ov.ResetTestState(); - - // Removal and Widget removal. - ov.RemoveChildView(&v2); - EXPECT_FALSE(ov.view_added()); - EXPECT_TRUE(ov.view_removed()); - EXPECT_EQ(&v2, ov.subject_view()); - - EXPECT_FALSE(v3.in_widget()); - EXPECT_EQ(NULL, v3.GetWidget()); -} -*/ - -TEST_F(ViewTest, IDs) { - const int kV1ID = 1; - const int kV2ID = 2; - const int kV3ID = 3; - const int kV4ID = 4; - const int kV5ID = 5; - const int kGroupID = 1; - View v1; - v1.set_id(kV1ID); - View v2; - v2.set_id(kV2ID); - View v3; - v3.set_id(kV3ID); - v3.set_group(kGroupID); - View v4; - v4.set_id(kV4ID); - v4.set_group(kGroupID); - v1.AddChildView(&v2); - v2.AddChildView(&v3); - v2.AddChildView(&v4); - - EXPECT_EQ(&v4, v1.GetViewByID(kV4ID)); - EXPECT_EQ(&v1, v1.GetViewByID(kV1ID)); - EXPECT_EQ(NULL, v1.GetViewByID(kV5ID)); // No V5 exists. - - View::Views views; - v1.GetViewsInGroup(kGroupID, &views); - EXPECT_EQ(2, views.size()); - View::Views::const_iterator it = std::find(views.begin(), views.end(), &v3); - EXPECT_NE(views.end(), it); - it = std::find(views.begin(), views.end(), &v4); - EXPECT_NE(views.end(), it); -} - -TEST_F(ViewTest, EventHandlers) { - -} - -TEST_F(ViewTest, Painting) { - -} - -} // namespace ui diff --git a/ui/views/widget/native_widget.h b/ui/views/widget/native_widget.h deleted file mode 100644 index 13f0d04..0000000 --- a/ui/views/widget/native_widget.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_H_ -#define UI_VIEWS_WIDGET_NATIVE_WIDGET_H_ - -#include "ui/gfx/native_widget_types.h" - -namespace gfx{ -class Path; -class Rect; -} - -namespace ui { -namespace internal { -class NativeWidgetListener; -} -class View; -class Widget; - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidget interface -// -// An interface implemented by an object that encapsulates rendering, event -// handling and widget management provided by an underlying native toolkit. -// -class NativeWidget { - public: - virtual ~NativeWidget() {} - - static NativeWidget* CreateNativeWidget( - internal::NativeWidgetListener* listener); - - // Retrieves the NativeWidget implementation associated with the given - // NativeView or Window, or NULL if the supplied handle has no associated - // NativeView. - static NativeWidget* GetNativeWidgetForNativeView( - gfx::NativeView native_view); - static NativeWidget* GetNativeWidgetForNativeWindow( - gfx::NativeWindow native_window); - - // Retrieves the top NativeWidget in the hierarchy containing the given - // NativeView, or NULL if there is no NativeWidget that contains it. - static NativeWidget* GetTopLevelNativeWidget(gfx::NativeView native_view); - - // See Widget for documentation and notes. - virtual void InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds) = 0; - virtual void InitWithWidgetParent(Widget* parent, - const gfx::Rect& bounds) = 0; - virtual void InitWithViewParent(View* parent, const gfx::Rect& bounds) = 0; - virtual void SetNativeWindowProperty(const char* name, void* value) = 0; - virtual void* GetNativeWindowProperty(const char* name) const = 0; - virtual gfx::Rect GetWindowScreenBounds() const = 0; - virtual gfx::Rect GetClientAreaScreenBounds() const = 0; - virtual void SetBounds(const gfx::Rect& bounds) = 0; - virtual void SetShape(const gfx::Path& shape) = 0; - virtual gfx::NativeView GetNativeView() const = 0; - virtual void Show() = 0; - virtual void Hide() = 0; - virtual void Close() = 0; - virtual void MoveAbove(NativeWidget* other) = 0; - virtual void SetAlwaysOnTop(bool always_on_top) = 0; - virtual bool IsVisible() const = 0; - virtual bool IsActive() const = 0; - virtual void SetMouseCapture() = 0; - virtual void ReleaseMouseCapture() = 0; - virtual bool HasMouseCapture() const = 0; - virtual bool ShouldReleaseCaptureOnMouseReleased() const = 0; - virtual void Invalidate() = 0; - virtual void InvalidateRect(const gfx::Rect& invalid_rect) = 0; - virtual void Paint() = 0; - virtual void FocusNativeView(gfx::NativeView native_view) = 0; - virtual Widget* GetWidget() const = 0; -}; - -} // namespace ui - -#endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_H_ - diff --git a/ui/views/widget/native_widget_listener.h b/ui/views/widget/native_widget_listener.h deleted file mode 100644 index d761f40..0000000 --- a/ui/views/widget/native_widget_listener.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_LISTENER_H_ -#define UI_VIEWS_WIDGET_NATIVE_WIDGET_LISTENER_H_ - -namespace gfx { -class Canvas; -class Point; -class Size; -} - -namespace ui { -class KeyEvent; -class MouseEvent; -class MouseWheelEvent; - -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetListener interface -// -// An interface implemented by the Widget that handles events sent from a -// NativeWidget implementation. -// -class NativeWidgetListener { - public: - virtual ~NativeWidgetListener() {} - - virtual void OnClose() = 0; - - virtual void OnDestroy() = 0; - virtual void OnDisplayChanged() = 0; - - virtual bool OnKeyEvent(const KeyEvent& event) = 0; - - virtual void OnMouseCaptureLost() = 0; - - virtual bool OnMouseEvent(const MouseEvent& event) = 0; - virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) = 0; - - virtual void OnNativeWidgetCreated() = 0; - - virtual void OnPaint(gfx::Canvas* canvas) = 0; - virtual void OnSizeChanged(const gfx::Size& size) = 0; - - virtual void OnNativeFocus(gfx::NativeView focused_view) = 0; - virtual void OnNativeBlur(gfx::NativeView focused_view) = 0; - - virtual void OnWorkAreaChanged() = 0; - - virtual Widget* GetWidget() const = 0; -}; - -} // namespace internal -} // namespace ui - -#endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_LISTENER_H_ diff --git a/ui/views/widget/native_widget_views.cc b/ui/views/widget/native_widget_views.cc deleted file mode 100644 index edb99fc..0000000 --- a/ui/views/widget/native_widget_views.cc +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -namespace ui { -namespace internal { - -} // namespace internal -} // namespace ui - diff --git a/ui/views/widget/native_widget_views.h b/ui/views/widget/native_widget_views.h deleted file mode 100644 index 766da05..0000000 --- a/ui/views/widget/native_widget_views.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_VIEWS_H_ -#define UI_VIEWS_WIDGET_NATIVE_WIDGET_VIEWS_H_ -#pragma once - -namespace ui { -namespace internal { - -} // namespace internal -} // namespace ui - -#endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_VIEWS_H_ diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc deleted file mode 100644 index dae81d1..0000000 --- a/ui/views/widget/native_widget_win.cc +++ /dev/null @@ -1,669 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/widget/native_widget_win.h" - -#include "base/memory/scoped_ptr.h" -#include "base/system_monitor/system_monitor.h" -#include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/native_theme_win.h" -#include "ui/gfx/path.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace ui { -namespace internal { - -namespace { - -// Called from NativeWidgetWin::Paint() to asynchronously redraw child windows. -BOOL CALLBACK EnumChildProcForRedraw(HWND hwnd, LPARAM lparam) { - DWORD process_id; - GetWindowThreadProcessId(hwnd, &process_id); - gfx::Rect invalid_rect = *reinterpret_cast<gfx::Rect*>(lparam); - - RECT window_rect; - GetWindowRect(hwnd, &window_rect); - invalid_rect.Offset(-window_rect.left, -window_rect.top); - - int flags = RDW_INVALIDATE | RDW_NOCHILDREN | RDW_FRAME; - if (process_id == GetCurrentProcessId()) - flags |= RDW_UPDATENOW; - RedrawWindow(hwnd, &invalid_rect.ToRECT(), NULL, flags); - return TRUE; -} - -// Links the HWND to its Widget. -const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__"; - -// A custom MSAA object id used to determine if a screen reader is actively -// listening for MSAA events. -const int kMSAAObjectID = 1; - -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, public: - -NativeWidgetWin::NativeWidgetWin(NativeWidgetListener* listener) - : listener_(listener), - active_mouse_tracking_flags_(0), - has_capture_(false) { -} - -NativeWidgetWin::~NativeWidgetWin() { -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, NativeWidget implementation: - -void NativeWidgetWin::InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds) { - WindowImpl::Init(parent, bounds); -} - -void NativeWidgetWin::InitWithWidgetParent(Widget* parent, - const gfx::Rect& bounds) { - InitWithNativeViewParent(parent->native_widget()->GetNativeView(), bounds); -} - -void NativeWidgetWin::InitWithViewParent(View* parent, - const gfx::Rect& bounds) { - InitWithWidgetParent(parent->GetWidget(), bounds); -} - -void NativeWidgetWin::SetNativeWindowProperty(const char* name, void* value) { - // Remove the existing property (if any). - for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { - if ((*i)->Key() == name) { - props_.erase(i); - break; - } - } - - if (value) - props_.push_back(new ViewProp(hwnd(), name, value)); -} - -void* NativeWidgetWin::GetNativeWindowProperty(const char* name) const { - return ViewProp::GetValue(hwnd(), name); -} - -gfx::Rect NativeWidgetWin::GetWindowScreenBounds() const { - RECT r; - GetWindowRect(hwnd(), &r); - return gfx::Rect(r); -} - -gfx::Rect NativeWidgetWin::GetClientAreaScreenBounds() const { - RECT r; - GetClientRect(hwnd(), &r); - POINT point = { r.left, r.top }; - ClientToScreen(hwnd(), &point); - return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); -} - -void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { - SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(), - bounds.height(), SWP_NOACTIVATE | SWP_NOZORDER); -} - -void NativeWidgetWin::SetShape(const gfx::Path& shape) { - SetWindowRgn(hwnd(), shape.CreateNativeRegion(), TRUE); -} - -gfx::NativeView NativeWidgetWin::GetNativeView() const { - return hwnd(); -} - -void NativeWidgetWin::Show() { - if (IsWindow(hwnd())) - ShowWindow(hwnd(), SW_SHOWNOACTIVATE); - // TODO(beng): move to windowposchanging to trap visibility changes instead. - if (IsLayeredWindow()) - Invalidate(); -} - -void NativeWidgetWin::Hide() { - if (IsWindow(hwnd())) { - // NOTE: Be careful not to activate any windows here (for example, calling - // ShowWindow(SW_HIDE) will automatically activate another window). This - // code can be called while a window is being deactivated, and activating - // another window will screw up the activation that is already in progress. - SetWindowPos(hwnd(), NULL, 0, 0, 0, 0, - SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | - SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); - } -} - -void NativeWidgetWin::Close() { - DestroyWindow(hwnd()); -} - -void NativeWidgetWin::MoveAbove(NativeWidget* other) { - SetWindowPos(hwnd(), other->GetNativeView(), 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); -} - -void NativeWidgetWin::SetAlwaysOnTop(bool always_on_top) { - DWORD style = always_on_top ? window_ex_style() | WS_EX_TOPMOST - : window_ex_style() & ~WS_EX_TOPMOST; - set_window_ex_style(style); - SetWindowLong(hwnd(), GWL_EXSTYLE, window_ex_style()); -} - -bool NativeWidgetWin::IsVisible() const { - return !!IsWindowVisible(hwnd()); -} - -bool NativeWidgetWin::IsActive() const { - WINDOWINFO info; - return ::GetWindowInfo(hwnd(), &info) && - ((info.dwWindowStatus & WS_ACTIVECAPTION) != 0); -} - -void NativeWidgetWin::SetMouseCapture() { - SetCapture(hwnd()); - has_capture_ = true; -} - -void NativeWidgetWin::ReleaseMouseCapture() { - ReleaseCapture(); - has_capture_ = false; -} - -bool NativeWidgetWin::HasMouseCapture() const { - return has_capture_; -} - -bool NativeWidgetWin::ShouldReleaseCaptureOnMouseReleased() const { - return true; -} - -void NativeWidgetWin::Invalidate() { - ::InvalidateRect(hwnd(), NULL, FALSE); -} - -void NativeWidgetWin::InvalidateRect(const gfx::Rect& invalid_rect) { - // InvalidateRect() expects client coordinates. - RECT r = invalid_rect.ToRECT(); - ::InvalidateRect(hwnd(), &r, FALSE); -} - -void NativeWidgetWin::Paint() { - RECT r; - GetUpdateRect(hwnd(), &r, FALSE); - if (!IsRectEmpty(&r)) { - // TODO(beng): WS_EX_TRANSPARENT windows (see WidgetWin::opaque_) - // Paint child windows that are in a different process asynchronously. - // This prevents a hang in other processes from blocking this process. - - // Calculate the invalid rect in screen coordinates before the first - // RedrawWindow() call to the parent HWND, since that will empty update_rect - // (which comes from a member variable) in the OnPaint call. - gfx::Rect screen_rect = GetWindowScreenBounds(); - gfx::Rect invalid_screen_rect(r); - invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y()); - - RedrawWindow(hwnd(), &r, NULL, - RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); - - LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect); - EnumChildWindows(hwnd(), EnumChildProcForRedraw, lparam); - } -} - -void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) { - if (IsWindow(native_view)) { - if (GetFocus() != native_view) - SetFocus(native_view); - } else { - // NULL or invalid |native_view| passed, we consider this to be clearing - // focus. Keep the top level window focused so we continue to receive - // key events. - SetFocus(hwnd()); - } -} - -Widget* NativeWidgetWin::GetWidget() const { - return listener_->GetWidget(); -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidetWin, MessageLoopForUI::Observer implementation - -void NativeWidgetWin::WillProcessMessage(const MSG& msg) { -} - -void NativeWidgetWin::DidProcessMessage(const MSG& msg) { - // We need to add ourselves as a message loop observer so that we can repaint - // aggressively if the contents of our window become invalid. Unfortunately - // WM_PAINT messages are starved and we get flickery redrawing when resizing - // if we do not do this. - Paint(); -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, message handlers: - -void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnActivateApp(BOOL active, DWORD thread_id) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnAppCommand(HWND window, short app_command, - WORD device, int keystate) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnCancelMode() { -} - -void NativeWidgetWin::OnCaptureChanged(HWND hwnd) { - has_capture_ = false; - listener_->OnMouseCaptureLost(); -} - -void NativeWidgetWin::OnClose() { - listener_->OnClose(); -} - -void NativeWidgetWin::OnCommand(UINT notification_code, int command_id, - HWND window) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) { - SetNativeWindowProperty(kNativeWidgetKey, this); - listener_->OnNativeWidgetCreated(); - MessageLoopForUI::current()->AddObserver(this); - return 0; -} - -void NativeWidgetWin::OnDestroy() { - // TODO(beng): drop_target_ - props_.reset(); -} - -void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { - listener_->OnDisplayChanged(); -} - -LRESULT NativeWidgetWin::OnDwmCompositionChanged(UINT message, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnEnterSizeMove() { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) { - // This is needed for magical win32 flicker ju-ju - return 1; -} - -void NativeWidgetWin::OnExitMenuLoop(BOOL is_track_popup_menu) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnExitSizeMove() { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnGetObject(UINT message, WPARAM w_param, - LPARAM l_param) { - return static_cast<LRESULT>(0L); -} - -void NativeWidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnHScroll(int scroll_type, short position, - HWND scrollbar) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnInitMenu(HMENU menu) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnInitMenuPopup(HMENU menu, UINT position, - BOOL is_system_menu) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnKeyDown(UINT message, WPARAM w_param, - LPARAM l_param) { - MSG msg = { message, w_param, l_param }; - SetMsgHandled(listener_->OnKeyEvent(KeyEvent(msg))); - return 0; -} - -LRESULT NativeWidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { - MSG msg = { message, w_param, l_param }; - SetMsgHandled(listener_->OnKeyEvent(KeyEvent(msg))); - return 0; -} - -void NativeWidgetWin::OnKillFocus(HWND focused_window) { - listener_->OnNativeBlur(focused_window); - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnMouseActivate(HWND window, UINT hittest_code, - UINT message) { - SetMsgHandled(FALSE); - return MA_ACTIVATE; -} - -LRESULT NativeWidgetWin::OnMouseLeave(UINT message, WPARAM w_param, - LPARAM l_param) { - // TODO(beng): tooltip - MSG msg = { message, w_param, l_param }; - SetMsgHandled(listener_->OnMouseEvent(MouseEvent(msg))); - - // Reset our tracking flag so that future mouse movement over this WidgetWin - // results in a new tracking session. - active_mouse_tracking_flags_ = 0; - - return 0; -} - -void NativeWidgetWin::OnMove(const CPoint& point) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnMoving(UINT param, LPRECT new_bounds) { -} - -LRESULT NativeWidgetWin::OnMouseRange(UINT message, WPARAM w_param, - LPARAM l_param) { - // TODO(beng): tooltips - ProcessMouseRange(message, w_param, l_param, false); - return 0; -} - -LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNCHitTest(UINT message, WPARAM w_param, - LPARAM l_param) { - LRESULT lr = DefWindowProc(hwnd(), message, w_param, l_param); - return lr; -} - -LRESULT NativeWidgetWin::OnNCMouseRange(UINT message, WPARAM w_param, - LPARAM l_param) { - bool processed = ProcessMouseRange(message, w_param, l_param, true); - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnNCPaint(HRGN rgn) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT message, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT message, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) { - // TODO(beng): tooltips - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnPaint(HDC dc) { - if (IsLayeredWindow()) { - // We need to clip to the dirty rect ourselves. - window_contents_->save(SkCanvas::kClip_SaveFlag); - RECT r; - GetUpdateRect(hwnd(), &r, FALSE); - window_contents_->ClipRectInt(gfx::Rect(r)); - listener_->OnPaint(window_contents_.get()); - window_contents_->restore(); - - RECT wr; - GetWindowRect(hwnd(), &wr); - SIZE size = {wr.right - wr.left, wr.bottom - wr.top}; - POINT position = {wr.left, wr.top}; - HDC dib_dc = window_contents_->BeginPlatformPaint(); - POINT zero = {0, 0}; - BLENDFUNCTION blend = {AC_SRC_OVER, 0, 125, AC_SRC_ALPHA}; - UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, - RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); - window_contents_->endPlatformPaint(); - } else { - scoped_ptr<gfx::CanvasPaint> canvas( - gfx::CanvasPaint::CreateCanvasPaint(hwnd())); - listener_->OnPaint(canvas->AsCanvas()); - } -} - -LRESULT NativeWidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) { - SystemMonitor* monitor = SystemMonitor::Get(); - if (monitor) - monitor->ProcessWmPowerBroadcastMessage(power_event); - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnReflectedMessage(UINT message, WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnSetFocus(HWND focused_window) { - listener_->OnNativeFocus(focused_window); - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { - if (flags == SPI_SETWORKAREA) - listener_->OnWorkAreaChanged(); - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnSize(UINT param, const CSize& size) { - gfx::Size s(size.cx, size.cy); - listener_->OnSizeChanged(s); - if (IsLayeredWindow()) { - window_contents_.reset( - new gfx::CanvasSkia(s.width(), s.height(), false)); - } -} - -void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnThemeChanged() { - gfx::NativeTheme::instance()->CloseHandles(); -} - -void NativeWidgetWin::OnVScroll(int scroll_type, short position, - HWND scrollbar) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnFinalMessage(HWND window) { - delete this; -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, WindowImpl overrides: - -HICON NativeWidgetWin::GetDefaultWindowIcon() const { - return NULL; -} - -LRESULT NativeWidgetWin::OnWndProc(UINT message, WPARAM w_param, - LPARAM l_param) { - LRESULT result = 0; - - // Otherwise we handle everything else. - if (!ProcessWindowMessage(hwnd(), message, w_param, l_param, result)) - result = DefWindowProc(hwnd(), message, w_param, l_param); - if (message == WM_NCDESTROY) { - MessageLoopForUI::current()->RemoveObserver(this); - OnFinalMessage(hwnd()); - } - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, private: - -void NativeWidgetWin::TrackMouseEvents(DWORD mouse_tracking_flags) { - // Begin tracking mouse events for this HWND so that we get WM_MOUSELEAVE - // when the user moves the mouse outside this HWND's bounds. - if (active_mouse_tracking_flags_ == 0 || mouse_tracking_flags & TME_CANCEL) { - if (mouse_tracking_flags & TME_CANCEL) { - // We're about to cancel active mouse tracking, so empty out the stored - // state. - active_mouse_tracking_flags_ = 0; - } else { - active_mouse_tracking_flags_ = mouse_tracking_flags; - } - - TRACKMOUSEEVENT tme; - tme.cbSize = sizeof(tme); - tme.dwFlags = mouse_tracking_flags; - tme.hwndTrack = hwnd(); - tme.dwHoverTime = 0; - TrackMouseEvent(&tme); - } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { - TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); - TrackMouseEvents(mouse_tracking_flags); - } -} - -bool NativeWidgetWin::ProcessMouseRange(UINT message, WPARAM w_param, - LPARAM l_param, bool non_client) { - MSG msg = { message, w_param, l_param }; - if (message == WM_MOUSEWHEEL) { - // Reroute the mouse-wheel to the window under the mouse pointer if - // applicable. - // TODO(beng): - //if (views::RerouteMouseWheel(hwnd(), w_param, l_param)) - // return 0; - return listener_->OnMouseWheelEvent(MouseWheelEvent(msg)); - } - // Windows only fires WM_MOUSELEAVE events if the application begins - // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. - // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. - if (!has_capture_) - TrackMouseEvents(non_client ? TME_NONCLIENT | TME_LEAVE : TME_LEAVE); - return listener_->OnMouseEvent(MouseEvent(msg)); -} - -void NativeWidgetWin::CloseNow() { - DestroyWindow(hwnd()); -} - -bool NativeWidgetWin::IsLayeredWindow() const { - return !!(window_ex_style() & WS_EX_LAYERED); -} - -} // namespace internal - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidget, public: - -// static -NativeWidget* NativeWidget::CreateNativeWidget( - internal::NativeWidgetListener* listener) { - return new internal::NativeWidgetWin(listener); -} - -// static -NativeWidget* NativeWidget::GetNativeWidgetForNativeView( - gfx::NativeView native_view) { - return reinterpret_cast<internal::NativeWidgetWin*>( - ViewProp::GetValue(native_view, internal::kNativeWidgetKey)); -} - -// static -NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow( - gfx::NativeWindow native_window) { - return GetNativeWidgetForNativeView(native_window); -} - -// static -NativeWidget* NativeWidget::GetTopLevelNativeWidget( - gfx::NativeView native_view) { - // First, check if the top-level window is a Widget. - HWND root = ::GetAncestor(native_view, GA_ROOT); - if (!root) - return NULL; - - NativeWidget* widget = GetNativeWidgetForNativeView(root); - if (widget) - return widget; - - // Second, try to locate the last Widget window in the parent hierarchy. - HWND parent_hwnd = native_view; - NativeWidget* parent_widget; - do { - parent_widget = GetNativeWidgetForNativeView(parent_hwnd); - if (parent_widget) { - widget = parent_widget; - parent_hwnd = ::GetAncestor(parent_hwnd, GA_PARENT); - } - } while (parent_hwnd != NULL && parent_widget != NULL); - - return widget; -} - -} // namespace ui diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h deleted file mode 100644 index bdd2e74..0000000 --- a/ui/views/widget/native_widget_win.h +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ -#define UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ - -#include "ui/base/win/window_impl.h" -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "base/message_loop.h" -#include "ui/views/widget/native_widget.h" - -namespace gfx { -class CanvasSkia; -} - -namespace ui { -class ViewProp; -class Widget; - -namespace internal { - -// A Windows message reflected from other windows. This message is sent with the -// following arguments: -// HWND - Target window -// MSG - kReflectedMessage -// WPARAM - Should be 0 -// LPARAM - Pointer to MSG struct containing the original message. -const int kReflectedMessage = WM_APP + 3; - -// These two messages aren't defined in winuser.h, but they are sent to windows -// with captions. They appear to paint the window caption and frame. -// Unfortunately if you override the standard non-client rendering as we do -// with CustomFrameWindow, sometimes Windows (not deterministically -// reproducibly but definitely frequently) will send these messages to the -// window and paint the standard caption/title over the top of the custom one. -// So we need to handle these messages in CustomFrameWindow to prevent this -// from happening. -const int WM_NCUAHDRAWCAPTION = 0xAE; -const int WM_NCUAHDRAWFRAME = 0xAF; - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin class -// -// A NativeWidget implementation that wraps a Win32 HWND. -// -class NativeWidgetWin : public NativeWidget, - public ui::WindowImpl, - public MessageLoopForUI::Observer { - public: - explicit NativeWidgetWin(NativeWidgetListener* listener); - virtual ~NativeWidgetWin(); - - private: - typedef ScopedVector<ViewProp> ViewProps; - - // Overridden from NativeWidget: - virtual void InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds); - virtual void InitWithWidgetParent(Widget* parent, - const gfx::Rect& bounds); - virtual void InitWithViewParent(View* parent, const gfx::Rect& bounds); - virtual void SetNativeWindowProperty(const char* name, void* value); - virtual void* GetNativeWindowProperty(const char* name) const; - virtual gfx::Rect GetWindowScreenBounds() const; - virtual gfx::Rect GetClientAreaScreenBounds() const; - virtual void SetBounds(const gfx::Rect& bounds); - virtual void SetShape(const gfx::Path& shape); - virtual gfx::NativeView GetNativeView() const; - virtual void Show(); - virtual void Hide(); - virtual void Close(); - virtual void MoveAbove(NativeWidget* other); - virtual void SetAlwaysOnTop(bool always_on_top); - virtual bool IsVisible() const; - virtual bool IsActive() const; - virtual void SetMouseCapture(); - virtual void ReleaseMouseCapture(); - virtual bool HasMouseCapture() const; - virtual bool ShouldReleaseCaptureOnMouseReleased() const; - virtual void Invalidate(); - virtual void InvalidateRect(const gfx::Rect& invalid_rect); - virtual void Paint(); - virtual void FocusNativeView(gfx::NativeView native_view); - virtual Widget* GetWidget() const; - - // Overridden from MessageLoop::Observer: - void WillProcessMessage(const MSG& msg); - virtual void DidProcessMessage(const MSG& msg); - - // Message handlers - BEGIN_MSG_MAP_EX(NativeWidgetWin) - // Range handlers must go first! - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) - MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMBUTTONDBLCLK, OnNCMouseRange) - - // Reflected message handler - MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage) - - // CustomFrameWindow hacks - MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) - MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) - - // Vista and newer - MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged) - - // Non-atlcrack.h handlers - MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) - MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseLeave) - MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) - - // Key events. - MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyDown) - MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyUp) - MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyDown); - MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyUp); - - // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. - MSG_WM_ACTIVATE(OnActivate) - MSG_WM_ACTIVATEAPP(OnActivateApp) - MSG_WM_APPCOMMAND(OnAppCommand) - MSG_WM_CANCELMODE(OnCancelMode) - MSG_WM_CAPTURECHANGED(OnCaptureChanged) - MSG_WM_CLOSE(OnClose) - MSG_WM_COMMAND(OnCommand) - MSG_WM_CREATE(OnCreate) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_DISPLAYCHANGE(OnDisplayChange) - MSG_WM_ERASEBKGND(OnEraseBkgnd) - MSG_WM_ENDSESSION(OnEndSession) - MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove) - MSG_WM_EXITMENULOOP(OnExitMenuLoop) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) - MSG_WM_HSCROLL(OnHScroll) - MSG_WM_INITMENU(OnInitMenu) - MSG_WM_INITMENUPOPUP(OnInitMenuPopup) - MSG_WM_KILLFOCUS(OnKillFocus) - MSG_WM_MOUSEACTIVATE(OnMouseActivate) - MSG_WM_MOVE(OnMove) - MSG_WM_MOVING(OnMoving) - MSG_WM_NCACTIVATE(OnNCActivate) - MSG_WM_NCCALCSIZE(OnNCCalcSize) - MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) - MSG_WM_NCPAINT(OnNCPaint) - MSG_WM_NOTIFY(OnNotify) - MSG_WM_PAINT(OnPaint) - MSG_WM_POWERBROADCAST(OnPowerBroadcast) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_SETICON(OnSetIcon) - MSG_WM_SETTEXT(OnSetText) - MSG_WM_SETTINGCHANGE(OnSettingChange) - MSG_WM_SIZE(OnSize) - MSG_WM_SYSCOMMAND(OnSysCommand) - MSG_WM_THEMECHANGED(OnThemeChanged) - MSG_WM_VSCROLL(OnVScroll) - MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) - MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) - END_MSG_MAP() - - virtual void OnActivate(UINT action, BOOL minimized, HWND window); - virtual void OnActivateApp(BOOL active, DWORD thread_id); - virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, - int keystate); - virtual void OnCancelMode(); - virtual void OnCaptureChanged(HWND hwnd); - virtual void OnClose(); - virtual void OnCommand(UINT notification_code, int command_id, HWND window); - virtual LRESULT OnCreate(CREATESTRUCT* create_struct); - // WARNING: If you override this be sure and invoke super, otherwise we'll - // leak a few things. - virtual void OnDestroy(); - virtual void OnDisplayChange(UINT bits_per_pixel, CSize screen_size); - virtual LRESULT OnDwmCompositionChanged(UINT message, - WPARAM w_param, - LPARAM l_param); - virtual void OnEndSession(BOOL ending, UINT logoff); - virtual void OnEnterSizeMove(); - virtual LRESULT OnEraseBkgnd(HDC dc); - virtual void OnExitMenuLoop(BOOL is_track_popup_menu); - virtual void OnExitSizeMove(); - virtual LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnGetMinMaxInfo(MINMAXINFO* minmax_info); - virtual void OnHScroll(int scroll_type, short position, HWND scrollbar); - virtual void OnInitMenu(HMENU menu); - virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu); - virtual LRESULT OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnKillFocus(HWND focused_window); - virtual LRESULT OnMouseActivate(HWND window, UINT hittest_code, UINT message); - virtual LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnMove(const CPoint& point); - virtual void OnMoving(UINT param, LPRECT new_bounds); - virtual LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCActivate(BOOL active); - virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param); - virtual LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCMouseRange(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnNCPaint(HRGN rgn); - virtual LRESULT OnNCUAHDrawCaption(UINT message, - WPARAM w_param, - LPARAM l_param); - virtual LRESULT OnNCUAHDrawFrame(UINT message, WPARAM w_param, - LPARAM l_param); - virtual LRESULT OnNotify(int w_param, NMHDR* l_param); - virtual void OnPaint(HDC dc); - virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data); - virtual LRESULT OnReflectedMessage(UINT message, WPARAM w_param, - LPARAM l_param); - virtual void OnSetFocus(HWND focused_window); - virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); - virtual LRESULT OnSetText(const wchar_t* text); - virtual void OnSettingChange(UINT flags, const wchar_t* section); - virtual void OnSize(UINT param, const CSize& size); - virtual void OnSysCommand(UINT notification_code, CPoint click); - virtual void OnThemeChanged(); - virtual void OnVScroll(int scroll_type, short position, HWND scrollbar); - virtual void OnWindowPosChanging(WINDOWPOS* window_pos); - virtual void OnWindowPosChanged(WINDOWPOS* window_pos); - - // Deletes this window as it is destroyed, override to provide different - // behavior. - virtual void OnFinalMessage(HWND window); - - // Overridden from WindowImpl: - virtual HICON GetDefaultWindowIcon() const; - virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); - - // Start tracking all mouse events so that this window gets sent mouse leave - // messages too. - void TrackMouseEvents(DWORD mouse_tracking_flags); - - bool ProcessMouseRange(UINT message, WPARAM w_param, LPARAM l_param, - bool non_client); - void ProcessMouseMoved(const CPoint& point, UINT flags, bool is_nonclient); - void ProcessMouseExited(); - - void CloseNow(); - - bool IsLayeredWindow() const; - - // A listener implementation that handles events received here. - NativeWidgetListener* listener_; - - // The flags currently being used with TrackMouseEvent to track mouse - // messages. 0 if there is no active tracking. The value of this member is - // used when tracking is canceled. - DWORD active_mouse_tracking_flags_; - - // True when the HWND has event capture. - bool has_capture_; - - // A canvas that contains the window contents in the case of a layered - // window. - scoped_ptr<gfx::CanvasSkia> window_contents_; - - // Properties associated with this NativeWidget implementation. - // TODO(beng): move to Widget. - ViewProps props_; - - DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin); -}; - -} // namespace internal -} // namespace ui - -#endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ - diff --git a/ui/views/widget/native_widget_win_unittest.cc b/ui/views/widget/native_widget_win_unittest.cc deleted file mode 100644 index da7e6ae..0000000 --- a/ui/views/widget/native_widget_win_unittest.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/win/window_impl.h" -#include "ui/views/view.h" -#include "ui/views/widget/native_widget.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_test_util.h" - -namespace ui { - -class NativeWidgetTest : public testing::Test { - public: - NativeWidgetTest() {} - virtual ~NativeWidgetTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(NativeWidgetTest); -}; - -class TestWindowImpl : public WindowImpl { - public: - TestWindowImpl() {} - virtual ~TestWindowImpl() {} - - virtual BOOL ProcessWindowMessage(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param, - LRESULT& result, - DWORD msg_mad_id = 0) { - return FALSE; - } - - private: - DISALLOW_COPY_AND_ASSIGN(TestWindowImpl); -}; - -TEST_F(NativeWidgetTest, CreateNativeWidget) { - scoped_ptr<Widget> widget(internal::CreateWidget()); - EXPECT_TRUE(widget->native_widget()->GetNativeView() != NULL); -} - -TEST_F(NativeWidgetTest, GetNativeWidgetForNativeView) { - scoped_ptr<Widget> widget(internal::CreateWidget()); - NativeWidget* a = widget->native_widget(); - HWND nv = widget->native_widget()->GetNativeView(); - NativeWidget* b = NativeWidget::GetNativeWidgetForNativeView(nv); - EXPECT_EQ(a, b); -} - -// |widget| has the toplevel NativeWidget. -TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) { - scoped_ptr<Widget> widget(internal::CreateWidget()); - EXPECT_EQ(widget->native_widget(), - NativeWidget::GetTopLevelNativeWidget( - widget->native_widget()->GetNativeView())); -} - -// |toplevel_widget| has the toplevel NativeWidget. -TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) { - scoped_ptr<Widget> child_widget(internal::CreateWidget()); - scoped_ptr<Widget> toplevel_widget(internal::CreateWidget()); - SetParent(child_widget->native_widget()->GetNativeView(), - toplevel_widget->native_widget()->GetNativeView()); - EXPECT_EQ(toplevel_widget->native_widget(), - NativeWidget::GetTopLevelNativeWidget( - child_widget->native_widget()->GetNativeView())); -} - -// |child_widget| has the toplevel NativeWidget. -TEST_F(NativeWidgetTest, GetTopLevelNativeWidget3) { - scoped_ptr<Widget> child_widget(internal::CreateWidget()); - - TestWindowImpl toplevel; - toplevel.Init(NULL, gfx::Rect(10, 10, 100, 100)); - - SetParent(child_widget->native_widget()->GetNativeView(), toplevel.hwnd()); - EXPECT_EQ(child_widget->native_widget(), - NativeWidget::GetTopLevelNativeWidget( - child_widget->native_widget()->GetNativeView())); -} - -} // namespace ui diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc deleted file mode 100644 index dd2ebf5..0000000 --- a/ui/views/widget/root_view.cc +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/widget/root_view.h" - -#include "ui/views/focus/focus_manager.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/widget/widget.h" - -namespace ui { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// RootView, public: - -RootView::RootView(Widget* widget, View* contents_view) - : widget_(widget), - mouse_pressed_handler_(NULL), - mouse_move_handler_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)), - focus_traversable_parent_(NULL), - focus_traversable_parent_view_(NULL) { - SetLayoutManager(new FillLayout); - AddChildView(contents_view); -} - -RootView::~RootView() { -} - -//////////////////////////////////////////////////////////////////////////////// -// RootView, View overrides: - -void RootView::OnViewRemoved(const View& parent, const View& child) { - if (&child == mouse_pressed_handler_) - mouse_pressed_handler_ = NULL; - - GetFocusManager()->RemoveView(&child); -} - -bool RootView::OnKeyPressed(const KeyEvent& event) { - return true; -} - -bool RootView::OnKeyReleased(const KeyEvent& event) { - return true; -} - -bool RootView::OnMouseWheel(const MouseWheelEvent& event) { - return true; -} - -bool RootView::OnMousePressed(const MouseEvent& event) { - bool handled = false; - - // Find the most View most tightly enclosing the event location that wants to - // handle events. - mouse_pressed_handler_ = GetEventHandlerForPoint(event.location()); - - // Walk up the tree from that View until we find one that handles it. - while (mouse_pressed_handler_ && mouse_pressed_handler_ != this) { - if (!mouse_pressed_handler_->enabled()) - break; - - MouseEvent target_event(event, this, mouse_pressed_handler_); - drag_info_.Reset(); - bool handled = mouse_pressed_handler_->MousePressed(target_event, - &drag_info_); - // MousePressed() may have resulted in the handler removing itself from the - // hierarchy, which will NULL-out |mouse_pressed_handler_|. - if (!mouse_pressed_handler_) - break; - - if (handled) - return true; - - mouse_pressed_handler_ = mouse_pressed_handler_->parent(); - } - return false; -} - -bool RootView::OnMouseDragged(const MouseEvent& event) { - // TODO(beng): Update cursor. - if (mouse_pressed_handler_) - return mouse_pressed_handler_->MouseDragged(event, &drag_info_); - return false; -} - -void RootView::OnMouseReleased(const MouseEvent& event) { - // TODO(beng): Update cursor. - if (mouse_pressed_handler_) { - MouseEvent released_event(event, this, mouse_pressed_handler_); - View* mouse_pressed_handler = mouse_pressed_handler_; - mouse_pressed_handler_ = NULL; - mouse_pressed_handler->MouseReleased(released_event); - } -} - -void RootView::OnMouseCaptureLost() { - if (mouse_pressed_handler_) { - View* mouse_pressed_handler = mouse_pressed_handler_; - mouse_pressed_handler_ = NULL; - mouse_pressed_handler->OnMouseCaptureLost(); - } -} - -void RootView::OnMouseMoved(const MouseEvent& event) { - // TODO(beng): Update cursor. - View* v = GetEventHandlerForPoint(event.location()); - while (v && !v->enabled() && (v != mouse_move_handler_)) - v = v->parent(); - if (v && v != this) { - if (v != mouse_move_handler_) { - OnMouseExited(event); - mouse_move_handler_ = v; - MouseEvent entered_event(event, this, mouse_move_handler_); - mouse_move_handler_->OnMouseEntered(entered_event); - } - MouseEvent moved_event(event, this, mouse_move_handler_); - mouse_move_handler_->OnMouseMoved(moved_event); - } else { - OnMouseExited(event); - } -} - -void RootView::OnMouseExited(const MouseEvent& event) { - if (mouse_move_handler_) { - MouseEvent exited_event(event, this, mouse_move_handler_); - mouse_move_handler_->OnMouseExited(exited_event); - mouse_move_handler_ = NULL; - } -} - -void RootView::Paint(gfx::Canvas* canvas) { - // Public pass-thru to protected base class method. - View::Paint(canvas); -} - -void RootView::InvalidateRect(const gfx::Rect& invalid_rect) { - widget_->InvalidateRect(invalid_rect); -} - -Widget* RootView::GetWidget() const { - return widget_; -} - -//////////////////////////////////////////////////////////////////////////////// -// RootView, FocusTraversable implementation: - -const FocusSearch* RootView::GetFocusSearch() const { - return &focus_search_; -} - -FocusTraversable* RootView::GetFocusTraversableParent() const { - return focus_traversable_parent_; -} - -View* RootView::GetFocusTraversableParentView() const { - return focus_traversable_parent_view_; -} - - -//////////////////////////////////////////////////////////////////////////////// -// RootView, private: - -} // namespace internal -} // namespace ui diff --git a/ui/views/widget/root_view.h b/ui/views/widget/root_view.h deleted file mode 100644 index 6838a65..0000000 --- a/ui/views/widget/root_view.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_ROOT_VIEW_H_ -#define UI_VIEWS_WIDGET_ROOT_VIEW_H_ -#pragma once - -#include "ui/views/focus/focus_manager.h" -#include "ui/views/focus/focus_search.h" -#include "ui/views/view.h" - -namespace ui { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// RootView class -// -// A View subclass that owns a View hierarchy. Used by the Widget to perform -// View-specific event tracking. -// -class RootView : public View, - public FocusTraversable { - public: - RootView(Widget* widget, View* contents_view); - virtual ~RootView(); - - // Overridden from View: - virtual void OnViewRemoved(const View& parent, const View& child) OVERRIDE; - virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; - virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE; - virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; - virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; - virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; - virtual void OnMouseCaptureLost() OVERRIDE; - virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; - virtual void Paint(gfx::Canvas* canvas) OVERRIDE; - virtual void InvalidateRect(const gfx::Rect& invalid_rect) OVERRIDE; - virtual Widget* GetWidget() const OVERRIDE; - - private: - // Overridden from FocusTraversable: - virtual const FocusSearch* GetFocusSearch() const OVERRIDE; - virtual FocusTraversable* GetFocusTraversableParent() const OVERRIDE; - virtual View* GetFocusTraversableParentView() const OVERRIDE; - - Widget* widget_; - - // The View that the mouse was pressed down on. Used to track drag operations - // and to target mouse-released events at the correct view. - View* mouse_pressed_handler_; - - // The View that the mouse is currently over. Used to track mouse-exited - // events as the mouse moves from view to view, and when the mouse leaves the - // bounds of the containing Widget. - View* mouse_move_handler_; - - // State captured on mouse press that would be useful for a potential drag - // operation. - DragInfo drag_info_; - - // - FocusSearch focus_search_; - - FocusTraversable* focus_traversable_parent_; - View* focus_traversable_parent_view_; - - DISALLOW_COPY_AND_ASSIGN(RootView); -}; - -} // namespace internal -} // namespace ui - -#endif // UI_VIEWS_WIDGET_ROOT_VIEW_H_ diff --git a/ui/views/widget/root_view_unittest.cc b/ui/views/widget/root_view_unittest.cc deleted file mode 100644 index 3c4e603..0000000 --- a/ui/views/widget/root_view_unittest.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_test_util.h" - -namespace ui { -namespace internal { - -class RootViewTest : public testing::Test { - public: - RootViewTest() {} - virtual ~RootViewTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(RootViewTest); -}; - -TEST_F(RootViewTest, FocusedViewResetOnViewRemoval) { - View v; - v.set_parent_owned(false); - scoped_ptr<Widget> widget(CreateWidgetWithContents(&v)); - - v.RequestFocus(); - - FocusManager* focus_manager = widget->GetFocusManager(); - EXPECT_TRUE(focus_manager != NULL); - EXPECT_EQ(&v, focus_manager->focused_view()); - - v.parent()->RemoveChildView(&v, false); - - EXPECT_NE(&v, focus_manager->focused_view()); - EXPECT_EQ(NULL, focus_manager->focused_view()); -} - -} // namespace internal -} // namespace ui diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc deleted file mode 100644 index 9871a2e..0000000 --- a/ui/views/widget/widget.cc +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/widget/widget.h" - -#include "base/bind.h" -#include "base/compiler_specific.h" -#include "base/message_loop.h" -#include "ui/views/focus/focus_manager.h" -#include "ui/views/view.h" -#include "ui/views/widget/native_widget.h" -#include "ui/views/widget/root_view.h" - -namespace ui { - -namespace { - -// TODO(beng): move to platform file -int GetHorizontalDragThreshold() { - static int threshold = -1; - if (threshold == -1) - threshold = GetSystemMetrics(SM_CXDRAG) / 2; - return threshold; -} - -// TODO(beng): move to platform file -int GetVerticalDragThreshold() { - static int threshold = -1; - if (threshold == -1) - threshold = GetSystemMetrics(SM_CYDRAG) / 2; - return threshold; -} - -bool ExceededDragThreshold(int delta_x, int delta_y) { - return (abs(delta_x) > GetHorizontalDragThreshold() || - abs(delta_y) > GetVerticalDragThreshold()); -} - -} - -//////////////////////////////////////////////////////////////////////////////// -// Widget, public: - -Widget::Widget(View* contents_view) - : ALLOW_THIS_IN_INITIALIZER_LIST( - native_widget_(NativeWidget::CreateNativeWidget(this))), - ALLOW_THIS_IN_INITIALIZER_LIST( - root_view_(new internal::RootView(this, contents_view))), - is_mouse_button_pressed_(false), - last_mouse_event_was_move_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), - delete_on_destroy_(true) { -} - -Widget::~Widget() { -} - -void Widget::InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds) { - native_widget_->InitWithNativeViewParent(parent, bounds); -} - -void Widget::InitWithWidgetParent(Widget* parent, const gfx::Rect& bounds) { - native_widget_->InitWithWidgetParent(parent, bounds); -} - -void Widget::InitWithViewParent(View* parent, const gfx::Rect& bounds) { - native_widget_->InitWithViewParent(parent, bounds); -} - -Widget* Widget::GetTopLevelWidget() const { - NativeWidget* native_widget = - NativeWidget::GetTopLevelNativeWidget(native_widget_->GetNativeView()); - return native_widget->GetWidget(); -} - -gfx::Rect Widget::GetWindowScreenBounds() const { - return native_widget_->GetWindowScreenBounds(); -} - -gfx::Rect Widget::GetClientAreaScreenBounds() const { - return native_widget_->GetClientAreaScreenBounds(); -} - -void Widget::SetBounds(const gfx::Rect& bounds) { - native_widget_->SetBounds(bounds); -} - -void Widget::SetShape(const gfx::Path& shape) { - native_widget_->SetShape(shape); -} - -void Widget::Show() { - native_widget_->Show(); -} - -void Widget::Hide() { - native_widget_->Hide(); -} - -void Widget::Close() { - native_widget_->Hide(); - - if (!close_widget_factory_.HasWeakPtrs()) { - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&Widget::CloseNow, close_widget_factory_.GetWeakPtr())); - } -} - -void Widget::MoveAbove(Widget* other) { - native_widget_->MoveAbove(other->native_widget()); -} - -void Widget::InvalidateRect(const gfx::Rect& invalid_rect) { - native_widget_->InvalidateRect(invalid_rect); -} - -ThemeProvider* Widget::GetThemeProvider() const { - return NULL; -} - -FocusManager* Widget::GetFocusManager() const { - return GetTopLevelWidget()->focus_manager_.get(); -} - -FocusTraversable* Widget::GetFocusTraversable() const { - return root_view_.get(); -} - -//////////////////////////////////////////////////////////////////////////////// -// Widget, NativeWidgetListener implementation: - -void Widget::OnClose() { - Close(); -} - -void Widget::OnDestroy() { - if (delete_on_destroy_) - delete this; -} - -void Widget::OnDisplayChanged() { - // TODO(beng): -} - -bool Widget::OnKeyEvent(const KeyEvent& event) { - // find root view. - - //return root_view_->OnKeyEvent(event); - return true; -} - -void Widget::OnMouseCaptureLost() { - if (native_widget_->HasMouseCapture()) { - if (is_mouse_button_pressed_) - root_view_->OnMouseCaptureLost(); - is_mouse_button_pressed_ = false; - } -} - -bool Widget::OnMouseEvent(const MouseEvent& event) { - switch (event.type()) { - case ui::Event::ET_MOUSE_PRESSED: - last_mouse_event_was_move_ = false; - if (root_view_->OnMousePressed(event)) { - is_mouse_button_pressed_ = true; - if (!native_widget_->HasMouseCapture()) - native_widget_->SetMouseCapture(); - return true; - } - return false; - case ui::Event::ET_MOUSE_RELEASED: - // TODO(beng): NativeWidgetGtk should not call this function if drag data - // exists, see comment in this function in NativeWidgetGtk. - // Release the capture first, that way we don't get confused if - // OnMouseReleased blocks. - if (native_widget_->HasMouseCapture() && - native_widget_->ShouldReleaseCaptureOnMouseReleased()) { - native_widget_->ReleaseMouseCapture(); - } - last_mouse_event_was_move_ = false; - is_mouse_button_pressed_ = false; - root_view_->OnMouseReleased(event); - return true; - case ui::Event::ET_MOUSE_MOVED: - if (native_widget_->HasMouseCapture() && is_mouse_button_pressed_) { - last_mouse_event_was_move_ = false; - root_view_->OnMouseDragged(event); - } else { - gfx::Point screen_loc(event.location()); - View::ConvertPointToScreen(*root_view_, &screen_loc); - if (last_mouse_event_was_move_ && - last_mouse_event_position_ == screen_loc) { - // Don't generate a mouse event for the same location as the last. - return true; - } - last_mouse_event_position_ = screen_loc; - last_mouse_event_was_move_ = true; - root_view_->OnMouseMoved(event); - } - break; - case ui::Event::ET_MOUSE_EXITED: - last_mouse_event_was_move_ = false; - root_view_->OnMouseExited(event); - return true; - } - return true; -} - -bool Widget::OnMouseWheelEvent(const MouseWheelEvent& event) { - return root_view_->OnMouseWheel(event); -} - -void Widget::OnNativeWidgetCreated() { - if (GetTopLevelWidget() == this) - focus_manager_.reset(new FocusManager(this)); -} - -void Widget::OnPaint(gfx::Canvas* canvas) { - root_view_->Paint(canvas); -} - -void Widget::OnSizeChanged(const gfx::Size& size) { - root_view_->SetSize(size); -} - -void Widget::OnNativeFocus(gfx::NativeView focused_view) { - GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( - focused_view, native_widget_->GetNativeView()); -} - -void Widget::OnNativeBlur(gfx::NativeView focused_view) { - GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( - native_widget_->GetNativeView(), focused_view); -} - -void Widget::OnWorkAreaChanged() { - -} - -Widget* Widget::GetWidget() const { - return const_cast<Widget*>(this); -} - -//////////////////////////////////////////////////////////////////////////////// -// Widget, private: - -void Widget::CloseNow() { - native_widget_->Close(); -} - -} // namespace ui - diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h deleted file mode 100644 index a5318d7..0000000 --- a/ui/views/widget/widget.h +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_WIDGET_H_ -#define UI_VIEWS_WIDGET_WIDGET_H_ - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/point.h" -#include "ui/views/focus/focus_manager.h" -#include "ui/views/widget/native_widget_listener.h" - -namespace gfx { -class Canvas; -class Path; -class Rect; -class Size; -} - -namespace ui { -namespace internal { -class RootView; -} -class FocusManager; -class KeyEvent; -class MouseEvent; -class MouseWheelEvent; -class NativeWidget; -class ThemeProvider; -class View; - -//////////////////////////////////////////////////////////////////////////////// -// Widget class -// -// Encapsulates the platform-specific rendering, event receiving and widget -// management aspects of the UI framework. -// -// Owns a RootView and thus a View hierarchy. Can contain child Widgets. -// Widget is a platform-independent type that communicates with a platform or -// context specific NativeWidget implementation. -// -// TODO(beng): Consider ownership of this object vs. NativeWidget. -class Widget : public internal::NativeWidgetListener { - public: - explicit Widget(View* contents_view); - virtual ~Widget(); - - void set_delete_on_destroy(bool delete_on_destroy) { - delete_on_destroy_ = delete_on_destroy; - } - - // Initialization. - void InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds); - void InitWithWidgetParent(Widget* parent, const gfx::Rect& bounds); - void InitWithViewParent(View* parent, const gfx::Rect& bounds); - - // Returns the topmost Widget in a hierarchy. - Widget* GetTopLevelWidget() const; - - // Returns the bounding rect of the Widget in screen coordinates. - gfx::Rect GetWindowScreenBounds() const; - - // Returns the bounding rect of the Widget's client area, in screen - // coordinates. - gfx::Rect GetClientAreaScreenBounds() const; - - // Sets the bounding rect of the Widget, in the coordinate system of its - // parent. - void SetBounds(const gfx::Rect& bounds); - - void SetShape(const gfx::Path& shape); - - void Show(); - void Hide(); - - void Close(); - - void MoveAbove(Widget* other); - void SetAlwaysOnTop(bool always_on_top); - - // Causes the specified rectangle to be added to the invalid rectangle for the - // Widget. - void InvalidateRect(const gfx::Rect& invalid_rect); - - // Returns a ThemeProvider that can be used to provide resources when - // rendering Views associated with this Widget. - ThemeProvider* GetThemeProvider() const; - - // Returns the FocusManager for this Widget. Only top-level Widgets have - // FocusManagers. - FocusManager* GetFocusManager() const; - - FocusTraversable* GetFocusTraversable() const; - - NativeWidget* native_widget() const { return native_widget_.get(); } - - private: - // Overridden from internal::NativeWidgetListener: - virtual void OnClose(); - virtual void OnDestroy(); - virtual void OnDisplayChanged(); - virtual bool OnKeyEvent(const KeyEvent& event); - virtual void OnMouseCaptureLost(); - virtual bool OnMouseEvent(const MouseEvent& event); - virtual bool OnMouseWheelEvent(const MouseWheelEvent& event); - virtual void OnNativeWidgetCreated(); - virtual void OnPaint(gfx::Canvas* canvas); - virtual void OnSizeChanged(const gfx::Size& size); - virtual void OnNativeFocus(gfx::NativeView focused_view); - virtual void OnNativeBlur(gfx::NativeView focused_view); - virtual void OnWorkAreaChanged(); - virtual Widget* GetWidget() const; - - // Causes the Widget to be destroyed immediately. - void CloseNow(); - - // A NativeWidget implementation. This can be changed dynamically to a - // different implementation during the lifetime of the Widget. - scoped_ptr<NativeWidget> native_widget_; - - // A RootView that owns the View hierarchy within this Widget. - scoped_ptr<internal::RootView> root_view_; - - // True when any mouse button is pressed. - bool is_mouse_button_pressed_; - - // The following are used to detect duplicate mouse move events and not - // deliver them. Displaying a window may result in the system generating - // duplicate move events even though the mouse hasn't moved. - bool last_mouse_event_was_move_; - gfx::Point last_mouse_event_position_; - - // Handles closing the Widget after a return to the message loop to allow the - // stack to unwind. - base::WeakPtrFactory<Widget> close_widget_factory_; - - // True if the Widget should be automatically deleted when it is destroyed. - bool delete_on_destroy_; - - scoped_ptr<FocusManager> focus_manager_; - - DISALLOW_COPY_AND_ASSIGN(Widget); -}; - -} // namespace ui - -#endif // UI_VIEWS_WIDGET_WIDGET_H_ - diff --git a/ui/views/widget/widget.rc b/ui/views/widget/widget.rc deleted file mode 100644 index c2bfa98..0000000 --- a/ui/views/widget/widget.rc +++ /dev/null @@ -1,9 +0,0 @@ -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -// PARTICULAR PURPOSE. -// -// Copyright (c) Microsoft Corporation. All rights reserved - -#include "ui/views/widget/widget_resource.h" -#include <windows.h> diff --git a/ui/views/widget/widget_resource.h b/ui/views/widget/widget_resource.h deleted file mode 100644 index aaf3ebc..0000000 --- a/ui/views/widget/widget_resource.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_WIDGET_RESOURCE_H_ -#define UI_VIEWS_WIDGET_WIDGET_RESOURCE_H_ -#pragma once - -#define IDR_PIXEL_SHADER 100 - -#endif // UI_VIEWS_WIDGET_WIDGET_RESOURCE_H_ diff --git a/ui/views/widget/widget_test_util.cc b/ui/views/widget/widget_test_util.cc deleted file mode 100644 index 19b49df..0000000 --- a/ui/views/widget/widget_test_util.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/widget/widget_test_util.h" - -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace ui { -namespace internal { - -Widget* CreateWidget() { - return CreateWidgetWithContents(new View); -} - -Widget* CreateWidgetWithContents(View* contents_view) { - Widget* widget = new Widget(contents_view); - widget->set_delete_on_destroy(false); - widget->InitWithNativeViewParent(NULL, gfx::Rect(10, 10, 200, 200)); - return widget; -} - -Widget* CreateWidgetWithParent(Widget* parent) { - Widget* widget = new Widget(new View); - widget->set_delete_on_destroy(false); - widget->InitWithWidgetParent(parent, gfx::Rect(10, 10, 200, 200)); - return widget; -} - -} // namespace internal -} // namespace ui diff --git a/ui/views/widget/widget_test_util.h b/ui/views/widget/widget_test_util.h deleted file mode 100644 index ca6a0d0..0000000 --- a/ui/views/widget/widget_test_util.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_WIDGET_WIDGET_TEST_UTIL_H_ -#define UI_VIEWS_WIDGET_WIDGET_TEST_UTIL_H_ -#pragma once - -namespace ui { -class View; -class Widget; -namespace internal { - -// Create dummy Widgets for use in testing. -Widget* CreateWidget(); -Widget* CreateWidgetWithContents(View* contents_view); -Widget* CreateWidgetWithParent(Widget* parent); - -} // namespace internal -} // namespace ui - -#endif // UI_VIEWS_WIDGET_WIDGET_TEST_UTIL_H_ diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc deleted file mode 100644 index 767aaa2..0000000 --- a/ui/views/widget/widget_unittest.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/views/focus/focus_manager.h" -#include "ui/views/widget/native_widget.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_test_util.h" - -namespace ui { - -class WidgetTest : public testing::Test { - public: - WidgetTest() {} - virtual ~WidgetTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(WidgetTest); -}; - -TEST_F(WidgetTest, FocusManagerInit_Basic) { - scoped_ptr<Widget> widget(internal::CreateWidget()); - EXPECT_TRUE(widget->GetFocusManager() != NULL); -} - -TEST_F(WidgetTest, FocusManagerInit_Nested) { - scoped_ptr<Widget> parent(internal::CreateWidget()); - scoped_ptr<Widget> child(internal::CreateWidgetWithParent(parent.get())); - - EXPECT_EQ(parent->GetFocusManager(), child->GetFocusManager()); -} - -} // namespace ui - diff --git a/ui/views/window/native_window.h b/ui/views/window/native_window.h deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/native_window.h +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. diff --git a/ui/views/window/native_window_views.cc b/ui/views/window/native_window_views.cc deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/native_window_views.cc +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. diff --git a/ui/views/window/native_window_views.h b/ui/views/window/native_window_views.h deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/native_window_views.h +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. diff --git a/ui/views/window/native_window_win.cc b/ui/views/window/native_window_win.cc deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/native_window_win.cc +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. diff --git a/ui/views/window/native_window_win.h b/ui/views/window/native_window_win.h deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/native_window_win.h +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. diff --git a/ui/views/window/window.cc b/ui/views/window/window.cc deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/window.cc +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. diff --git a/ui/views/window/window.h b/ui/views/window/window.h deleted file mode 100644 index 7a37f38..0000000 --- a/ui/views/window/window.h +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. |