From 4d0bd1045bc0df8daea2a5626e73906cb074631b Mon Sep 17 00:00:00 2001 From: "ben@chromium.org" Date: Thu, 16 Oct 2008 00:26:30 +0000 Subject: Rename ViewContainer to Container and HWNDViewContainer to ContainerWin. http://crbug.com/3430 Review URL: http://codereview.chromium.org/7376 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3441 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/views/SConscript | 2 +- chrome/views/accessibility/view_accessibility.cc | 8 +- chrome/views/aero_tooltip_manager.cc | 2 +- chrome/views/aero_tooltip_manager.h | 2 +- chrome/views/bitmap_scroll_bar.cc | 8 +- chrome/views/button.cc | 2 +- chrome/views/button_dropdown.cc | 8 +- chrome/views/chrome_menu.cc | 14 +- chrome/views/chrome_menu.h | 8 +- chrome/views/client_view.cc | 6 +- chrome/views/container.h | 85 +++ chrome/views/container_win.cc | 916 ++++++++++++++++++++++ chrome/views/container_win.h | 586 ++++++++++++++ chrome/views/custom_frame_window.cc | 8 +- chrome/views/custom_frame_window.h | 2 +- chrome/views/dialog_client_view.cc | 2 +- chrome/views/focus_manager.cc | 8 +- chrome/views/focus_manager.h | 6 +- chrome/views/focus_manager_unittest.cc | 10 +- chrome/views/hwnd_view.cc | 14 +- chrome/views/hwnd_view_container.cc | 928 ----------------------- chrome/views/hwnd_view_container.h | 586 -------------- chrome/views/label.cc | 2 +- chrome/views/menu_button.cc | 6 +- chrome/views/native_control.cc | 8 +- chrome/views/native_scroll_bar.cc | 10 +- chrome/views/root_view.cc | 26 +- chrome/views/root_view.h | 40 +- chrome/views/root_view_drop_target.cc | 4 +- chrome/views/tabbed_pane.cc | 4 +- chrome/views/tabbed_pane.h | 4 +- chrome/views/table_view.cc | 2 +- chrome/views/text_button.cc | 2 +- chrome/views/text_field.cc | 8 +- chrome/views/tooltip_manager.cc | 22 +- chrome/views/tooltip_manager.h | 10 +- chrome/views/tree_view.cc | 4 +- chrome/views/view.cc | 32 +- chrome/views/view.h | 22 +- chrome/views/view_container.h | 86 --- chrome/views/view_unittest.cc | 8 +- chrome/views/views.vcproj | 24 +- chrome/views/window.cc | 30 +- chrome/views/window.h | 14 +- 44 files changed, 1782 insertions(+), 1797 deletions(-) create mode 100644 chrome/views/container.h create mode 100644 chrome/views/container_win.cc create mode 100644 chrome/views/container_win.h delete mode 100644 chrome/views/hwnd_view_container.cc delete mode 100644 chrome/views/hwnd_view_container.h delete mode 100644 chrome/views/view_container.h (limited to 'chrome/views') diff --git a/chrome/views/SConscript b/chrome/views/SConscript index 3963a77..832db30 100644 --- a/chrome/views/SConscript +++ b/chrome/views/SConscript @@ -45,6 +45,7 @@ input_files = [ 'chrome_menu.cc', 'client_view.cc', 'combo_box.cc', + 'container_win.cc', 'custom_frame_window.cc', 'dialog_delegate.cc', 'dialog_client_view.cc', @@ -55,7 +56,6 @@ input_files = [ 'grid_layout.cc', 'group_table_view.cc', 'hwnd_view.cc', - 'hwnd_view_container.cc', 'image_view.cc', 'label.cc', 'layout_manager.cc', diff --git a/chrome/views/accessibility/view_accessibility.cc b/chrome/views/accessibility/view_accessibility.cc index af502fc..838995a 100644 --- a/chrome/views/accessibility/view_accessibility.cc +++ b/chrome/views/accessibility/view_accessibility.cc @@ -109,9 +109,9 @@ STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) { ChromeViews::View* parent = view_->GetParent(); if (!parent) { - // This function can get called during teardown of HWNDViewContainer so - // we should bail out if we fail to get the HWND. - if (!view_->GetViewContainer() || !view_->GetViewContainer()->GetHWND()) { + // This function can get called during teardown of ContainerWin so we + // should bail out if we fail to get the HWND. + if (!view_->GetContainer() || !view_->GetContainer()->GetHWND()) { *disp_parent = NULL; return S_FALSE; } @@ -120,7 +120,7 @@ STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) { // the default implementation, to interface with Windows' hierarchy and to // support calls from e.g. WindowFromAccessibleObject. HRESULT hr = - ::AccessibleObjectFromWindow(view_->GetViewContainer()->GetHWND(), + ::AccessibleObjectFromWindow(view_->GetContainer()->GetHWND(), OBJID_WINDOW, IID_IAccessible, reinterpret_cast(disp_parent)); diff --git a/chrome/views/aero_tooltip_manager.cc b/chrome/views/aero_tooltip_manager.cc index cf446d8..7929786 100644 --- a/chrome/views/aero_tooltip_manager.cc +++ b/chrome/views/aero_tooltip_manager.cc @@ -18,7 +18,7 @@ namespace ChromeViews { /////////////////////////////////////////////////////////////////////////////// // AeroTooltipManager, public: -AeroTooltipManager::AeroTooltipManager(ViewContainer* container, HWND parent) +AeroTooltipManager::AeroTooltipManager(Container* container, HWND parent) : TooltipManager(container, parent), initial_delay_(0) { } diff --git a/chrome/views/aero_tooltip_manager.h b/chrome/views/aero_tooltip_manager.h index 136db2e..2f2f29a 100644 --- a/chrome/views/aero_tooltip_manager.h +++ b/chrome/views/aero_tooltip_manager.h @@ -28,7 +28,7 @@ namespace ChromeViews { // TODO(glen): Resolve this with Microsoft. class AeroTooltipManager : public ChromeViews::TooltipManager { public: - AeroTooltipManager(ViewContainer* container, HWND parent); + AeroTooltipManager(Container* container, HWND parent); virtual ~AeroTooltipManager(); void OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param); diff --git a/chrome/views/bitmap_scroll_bar.cc b/chrome/views/bitmap_scroll_bar.cc index 699d986..87b1c5a 100644 --- a/chrome/views/bitmap_scroll_bar.cc +++ b/chrome/views/bitmap_scroll_bar.cc @@ -7,9 +7,9 @@ #include "base/message_loop.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" +#include "chrome/views/container.h" #include "chrome/views/menu.h" #include "chrome/views/scroll_view.h" -#include "chrome/views/view_container.h" #include "skia/include/SkBitmap.h" #include "generated_resources.h" @@ -534,14 +534,14 @@ enum ScrollBarContextMenuCommands { void BitmapScrollBar::ShowContextMenu(View* source, int x, int y, bool is_mouse_gesture) { - ViewContainer* vc = GetViewContainer(); + Container* vc = GetContainer(); CRect vc_bounds; vc->GetBounds(&vc_bounds, true); gfx::Point temp_pt(x - vc_bounds.left, y - vc_bounds.top); - View::ConvertPointFromViewContainer(this, &temp_pt); + View::ConvertPointFromContainer(this, &temp_pt); context_menu_mouse_position_ = IsHorizontal() ? temp_pt.x() : temp_pt.y(); - Menu menu(this, Menu::TOPLEFT, GetViewContainer()->GetHWND()); + Menu menu(this, Menu::TOPLEFT, GetContainer()->GetHWND()); menu.AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollHere); menu.AppendSeparator(); menu.AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollStart); diff --git a/chrome/views/button.cc b/chrome/views/button.cc index 0cc98ae..4cc1bde 100644 --- a/chrome/views/button.cc +++ b/chrome/views/button.cc @@ -11,8 +11,8 @@ #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/throb_animation.h" +#include "chrome/views/container.h" #include "chrome/views/event.h" -#include "chrome/views/view_container.h" #include "chrome/app/chrome_dll_resource.h" #include "generated_resources.h" diff --git a/chrome/views/button_dropdown.cc b/chrome/views/button_dropdown.cc index a2d473b..bea4001 100644 --- a/chrome/views/button_dropdown.cc +++ b/chrome/views/button_dropdown.cc @@ -7,8 +7,8 @@ #include "base/message_loop.h" #include "chrome/browser/back_forward_menu_model.h" #include "chrome/common/l10n_util.h" +#include "chrome/views/container.h" #include "chrome/views/view_menu_delegate.h" -#include "chrome/views/view_container.h" #include "generated_resources.h" @@ -49,7 +49,7 @@ bool ButtonDropDown::OnMousePressed(const ChromeViews::MouseEvent& e) { // Schedule a task that will show the menu. MessageLoop::current()->PostDelayedTask(FROM_HERE, show_menu_factory_.NewRunnableMethod(&ButtonDropDown::ShowDropDownMenu, - GetViewContainer()->GetHWND()), + GetContainer()->GetHWND()), kMenuTimerDelay); } @@ -74,7 +74,7 @@ void ButtonDropDown::OnMouseReleased(const ChromeViews::MouseEvent& e, // update the appearance synchronously. SetState(BS_PUSHED); PaintNow(); - ShowDropDownMenu(GetViewContainer()->GetHWND()); + ShowDropDownMenu(GetContainer()->GetHWND()); } } @@ -92,7 +92,7 @@ bool ButtonDropDown::OnMouseDragged(const ChromeViews::MouseEvent& e) { // it immediately. if (e.y() > y_position_on_lbuttondown_ + dragging_threshold) { show_menu_factory_.RevokeAll(); - ShowDropDownMenu(GetViewContainer()->GetHWND()); + ShowDropDownMenu(GetContainer()->GetHWND()); } } diff --git a/chrome/views/chrome_menu.cc b/chrome/views/chrome_menu.cc index 0b0d4ff..72519d5 100644 --- a/chrome/views/chrome_menu.cc +++ b/chrome/views/chrome_menu.cc @@ -21,7 +21,7 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/os_exchange_data.h" #include "chrome/views/border.h" -#include "chrome/views/hwnd_view_container.h" +#include "chrome/views/container_win.h" #include "chrome/views/root_view.h" #include "generated_resources.h" @@ -517,7 +517,7 @@ class MenuSeparator : public View { class MenuHostRootView : public RootView { public: - explicit MenuHostRootView(ViewContainer* container, + explicit MenuHostRootView(Container* container, SubmenuView* submenu) : RootView(container), submenu_(submenu), @@ -623,7 +623,7 @@ class MenuHostRootView : public RootView { // DelayedClosed, which avoids timing issues with deleting the window while // capture or events are directed at it. -class MenuHost : public HWNDViewContainer { +class MenuHost : public ContainerWin { public: MenuHost(SubmenuView* submenu) : closed_(false), @@ -647,7 +647,7 @@ class MenuHost : public HWNDViewContainer { const gfx::Rect& bounds, View* contents_view, bool do_capture) { - HWNDViewContainer::Init(parent, bounds, true); + ContainerWin::Init(parent, bounds, true); SetContentsView(contents_view); // We don't want to take focus away from the hosting window. ShowWindow(SW_SHOWNA); @@ -674,11 +674,11 @@ class MenuHost : public HWNDViewContainer { GetRootView()->RemoveAllChildViews(false); closed_ = true; ReleaseCapture(); - HWNDViewContainer::Hide(); + ContainerWin::Hide(); } virtual void OnCaptureChanged(HWND hwnd) { - HWNDViewContainer::OnCaptureChanged(hwnd); + ContainerWin::OnCaptureChanged(hwnd); owns_capture_ = false; #ifdef DEBUG_MENU DLOG(INFO) << "Capture changed"; @@ -2559,7 +2559,7 @@ bool MenuController::IsMenuWindow(MenuItemView* item, HWND window) { if (!item) return false; return ((item->HasSubmenu() && item->GetSubmenu()->IsShowing() && - item->GetSubmenu()->GetViewContainer()->GetHWND() == window) || + item->GetSubmenu()->GetContainer()->GetHWND() == window) || IsMenuWindow(item->GetParentMenuItem(), window)); } diff --git a/chrome/views/chrome_menu.h b/chrome/views/chrome_menu.h index 1c49188..75bec86 100644 --- a/chrome/views/chrome_menu.h +++ b/chrome/views/chrome_menu.h @@ -19,7 +19,7 @@ namespace ChromeViews { -class HWNDViewContainer; +class ContainerWin; class MenuController; class MenuItemView; class SubmenuView; @@ -477,8 +477,8 @@ class MenuItemView : public View { // . Forwards the appropriate events to the MenuController. This allows the // MenuController to update the selection as the user moves the mouse around. // . Renders the drop indicator during a drop operation. -// . Shows and hides the window (an HWNDViewContainer) when the menu is -// shown on screen. +// . Shows and hides the window (a ContainerWin) when the menu is shown on +// screen. // // SubmenuView is itself contained in a MenuScrollViewContainer. // MenuScrollViewContainer handles showing as much of the SubmenuView as the @@ -571,7 +571,7 @@ class SubmenuView : public View { // Parent menu item. MenuItemView* parent_menu_item_; - // HWNDViewContainer subclass used to show the children. + // ContainerWin subclass used to show the children. MenuHost* host_; // If non-null, indicates a drop is in progress and drop_item is the item diff --git a/chrome/views/client_view.cc b/chrome/views/client_view.cc index 5072acd..29953cc 100644 --- a/chrome/views/client_view.cc +++ b/chrome/views/client_view.cc @@ -24,7 +24,7 @@ int ClientView::NonClientHitTest(const gfx::Point& point) { gfx::Size ClientView::GetPreferredSize() { // |contents_view_| is allowed to be NULL up until the point where this view - // is attached to a ViewContainer. + // is attached to a Container. if (contents_view_) return contents_view_->GetPreferredSize(); return gfx::Size(); @@ -32,7 +32,7 @@ gfx::Size ClientView::GetPreferredSize() { void ClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { if (is_add && child == this) { - DCHECK(GetViewContainer()); + DCHECK(GetContainer()); DCHECK(contents_view_); // |contents_view_| must be valid now! AddChildView(contents_view_); } @@ -44,7 +44,7 @@ void ClientView::DidChangeBounds(const CRect& previous, const CRect& current) { void ClientView::Layout() { // |contents_view_| is allowed to be NULL up until the point where this view - // is attached to a ViewContainer. + // is attached to a Container. if (contents_view_) contents_view_->SetBounds(0, 0, width(), height()); } diff --git a/chrome/views/container.h b/chrome/views/container.h new file mode 100644 index 0000000..b4d6e29 --- /dev/null +++ b/chrome/views/container.h @@ -0,0 +1,85 @@ +// Copyright (c) 2006-2008 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 CHROME_VIEWS_CONTAINER_H_ +#define CHROME_VIEWS_CONTAINER_H_ + +// TODO(maruel): Remove once HWND is abstracted. +#include + +// TODO(maruel): Remove once gfx::Rect is used instead. +namespace WTL { +class CRect; +} +using WTL::CRect; + +namespace ChromeViews { + +class RootView; +class TooltipManager; +class Accelerator; + +///////////////////////////////////////////////////////////////////////////// +// +// Container interface +// +// Container is an abstract class that defines the API that should be +// implemented by a CWindow / HWND implementation in order to host a view +// hierarchy. +// +// Container wraps a hierarchy of View objects (see view.h) that implement +// painting and flexible layout within the bounds of the Container's window. +// +// The Container is responsible for handling various system events and +// forwarding them to the appropriate view. +// +///////////////////////////////////////////////////////////////////////////// + +class Container { + public: + virtual ~Container() { } + + // Returns the bounds of this container in the screen coordinate system. + // If the receiving view container is a frame which is larger than its + // client area, this method returns the client area if including_frame is + // false and the frame bounds otherwise. If the receiving view container + // is not a frame, including_frame is ignored. + virtual void GetBounds(CRect *out, bool including_frame) const = 0; + + // Moves this view container to the front of the Z-Order + // If should_activate is TRUE, the window should also become the active + // window + virtual void MoveToFront(bool should_activate) = 0; + + // Returns the Window HWND associated with this container + virtual HWND GetHWND() const = 0; + + // Forces a paint of a specified rectangle immediately. + virtual void PaintNow(const CRect& update_rect) = 0; + + // Returns the RootView contained by this container + virtual RootView* GetRootView() = 0; + + // Returns whether the view container is visible to the user + virtual bool IsVisible() = 0; + + // Returns whether the view container is the currently active window. + virtual bool IsActive() = 0; + + // Returns the TooltipManager for this Container. If this Container does not + // support tooltips, NULL is returned. + virtual TooltipManager* GetTooltipManager() { + return NULL; + } + + // Returns the accelerator given a command id. Returns false if there is + // no accelerator associated with a given id, which is a common condition. + virtual bool GetAccelerator(int cmd_id, + Accelerator* accelerator) = 0; +}; + +} // namespace ChromeViews + +#endif // CHROME_VIEWS_VIEW_CONTAINER_H_ + diff --git a/chrome/views/container_win.cc b/chrome/views/container_win.cc new file mode 100644 index 0000000..4506b80 --- /dev/null +++ b/chrome/views/container_win.cc @@ -0,0 +1,916 @@ +// Copyright (c) 2006-2008 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 "chrome/views/container_win.h" + +#include "base/gfx/native_theme.h" +#include "base/string_util.h" +#include "base/win_util.h" +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/gfx/chrome_canvas.h" +#include "chrome/common/win_util.h" +#include "chrome/views/aero_tooltip_manager.h" +#include "chrome/views/accessibility/view_accessibility.h" +#include "chrome/views/hwnd_notification_source.h" +#include "chrome/views/root_view.h" + +namespace ChromeViews { + +static const DWORD kWindowDefaultChildStyle = + WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; +static const DWORD kWindowDefaultStyle = WS_OVERLAPPEDWINDOW; +static const DWORD kWindowDefaultExStyle = 0; + +// Property used to link the HWND to its RootView. +static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; + +bool SetRootViewForHWND(HWND hwnd, RootView* root_view) { + return ::SetProp(hwnd, kRootViewWindowProperty, root_view) ? true : false; +} + +RootView* GetRootViewForHWND(HWND hwnd) { + return reinterpret_cast(::GetProp(hwnd, kRootViewWindowProperty)); +} + +// Used to locate the ContainerWin issuing the current Create. Only valid for +// the life of Create. +// +// This obviously assumes we only create ContainerWins from the same thread, +// which is currently the case. +static ContainerWin* instance_issuing_create = NULL; + +/////////////////////////////////////////////////////////////////////////////// +// FillLayout + +FillLayout::FillLayout() { +} + +FillLayout::~FillLayout() { +} + +void FillLayout::Layout(View* host) { + CRect bounds; + host->GetContainer()->GetBounds(&bounds, false); + if (host->GetChildViewCount() == 0) + return; + + View* frame_view = host->GetChildViewAt(0); + frame_view->SetBounds(CRect(CPoint(0, 0), bounds.Size())); +} + +gfx::Size FillLayout::GetPreferredSize(View* host) { + DCHECK(host->GetChildViewCount() == 1); + return host->GetChildViewAt(0)->GetPreferredSize(); +} + +/////////////////////////////////////////////////////////////////////////////// +// Window class tracking. + +// static +const wchar_t* const ContainerWin::kBaseClassName = + L"Chrome_ContainerWin_"; + +// Window class information used for registering unique windows. +struct ClassInfo { + UINT style; + HBRUSH background; + + explicit ClassInfo(int style) + : style(style), + background(NULL) {} + + // Compares two ClassInfos. Returns true if all members match. + bool Equals(const ClassInfo& other) { + return (other.style == style && other.background == background); + } +}; + +// Represents a registered window class. +struct RegisteredClass { + RegisteredClass(const ClassInfo& info, + const std::wstring& name, + ATOM atom) + : info(info), + name(name), + atom(atom) { + } + + // Info used to create the class. + ClassInfo info; + + // The name given to the window. + std::wstring name; + + // The ATOM returned from creating the window. + ATOM atom; +}; + +typedef std::list RegisteredClasses; + +// The list of registered classes. +static RegisteredClasses* registered_classes = NULL; + + +/////////////////////////////////////////////////////////////////////////////// +// ContainerWin, public + +ContainerWin::ContainerWin() + : active_mouse_tracking_flags_(0), + has_capture_(false), + current_action_(FA_NONE), + toplevel_(false), + window_style_(0), + window_ex_style_(kWindowDefaultExStyle), + layered_(false), + layered_alpha_(255), + delete_on_destroy_(true), + can_update_layered_window_(true), + last_mouse_event_was_move_(false), + is_mouse_down_(false), + class_style_(CS_DBLCLKS), + hwnd_(NULL), + close_container_factory_(this) { +} + +ContainerWin::~ContainerWin() { + MessageLoopForUI::current()->RemoveObserver(this); +} + +void ContainerWin::Init(HWND parent, const gfx::Rect& bounds, + bool has_own_focus_manager) { + toplevel_ = parent == NULL; + + if (window_style_ == 0) + window_style_ = toplevel_ ? kWindowDefaultStyle : kWindowDefaultChildStyle; + + // See if the style has been overridden. + opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); + layered_ = !!(window_ex_style_ & WS_EX_LAYERED); + + // Force creation of the RootView if it hasn't been created yet. + GetRootView(); + + // Ensures the parent we have been passed is valid, otherwise CreateWindowEx + // will fail. + if (parent && !::IsWindow(parent)) { + NOTREACHED() << "invalid parent window specified."; + parent = NULL; + } + + hwnd_ = CreateWindowEx(window_ex_style_, GetWindowClassName().c_str(), L"", + window_style_, bounds.x(), bounds.y(), bounds.width(), + bounds.height(), parent, NULL, NULL, this); + DCHECK(hwnd_); + // The window procedure should have set the data for us. + DCHECK(win_util::GetWindowUserData(hwnd_) == this); + + root_view_->OnContainerCreated(); + + if (has_own_focus_manager) { + ChromeViews::FocusManager::CreateFocusManager(hwnd_, GetRootView()); + } else { + // Subclass the window so we get the tab key messages when a view with no + // associated native window is focused. + FocusManager::InstallFocusSubclass(hwnd_, NULL); + } + + // Sets the RootView as a property, so the automation can introspect windows. + SetRootViewForHWND(hwnd_, root_view_.get()); + + MessageLoopForUI::current()->AddObserver(this); + + // Windows special DWM window frame requires a special tooltip manager so + // that window controls in Chrome windows don't flicker when you move your + // mouse over them. See comment in aero_tooltip_manager.h. + if (win_util::ShouldUseVistaFrame()) { + tooltip_manager_.reset(new AeroTooltipManager(this, GetHWND())); + } else { + tooltip_manager_.reset(new TooltipManager(this, GetHWND())); + } + + // This message initializes the window so that focus border are shown for + // windows. + ::SendMessage(GetHWND(), + WM_CHANGEUISTATE, + MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), + 0); + + // Bug 964884: detach the IME attached to this window. + // We should attach IMEs only when we need to input CJK strings. + ::ImmAssociateContextEx(GetHWND(), NULL, 0); +} + +void ContainerWin::SetContentsView(View* view) { + DCHECK(view && hwnd_) << "Can't be called until after the HWND is created!"; + // The ContentsView must be set up _after_ the window is created so that its + // Container pointer is valid. + root_view_->SetLayoutManager(new FillLayout); + if (root_view_->GetChildViewCount() != 0) + root_view_->RemoveAllChildViews(true); + root_view_->AddChildView(view); + + // Manually size the window here to ensure the root view is laid out. + RECT wr; + GetWindowRect(&wr); + ChangeSize(0, CSize(wr.right - wr.left, wr.bottom - wr.top)); +} + +/////////////////////////////////////////////////////////////////////////////// +// ChromeViews::Container implementation: + +void ContainerWin::GetBounds(CRect *out, bool including_frame) const { + if (including_frame) { + GetWindowRect(out); + } else { + GetClientRect(out); + + POINT p = {0, 0}; + ::ClientToScreen(hwnd_, &p); + + out->left += p.x; + out->top += p.y; + out->right += p.x; + out->bottom += p.y; + } +} + +void ContainerWin::MoveToFront(bool should_activate) { + int flags = SWP_NOMOVE | SWP_NOSIZE; + if (!should_activate) { + flags |= SWP_NOACTIVATE; + } + SetWindowPos(HWND_NOTOPMOST, 0, 0, 0, 0, flags); +} + +HWND ContainerWin::GetHWND() const { + return hwnd_; +} + +void ContainerWin::PaintNow(const CRect& update_rect) { + if (layered_) { + PaintLayeredWindow(); + } else if (root_view_->NeedsPainting(false) && IsWindow()) { + if (!opaque_ && GetParent()) { + // We're transparent. Need to force painting to occur from our parent. + CRect parent_update_rect = update_rect; + POINT location_in_parent = { 0, 0 }; + ClientToScreen(hwnd_, &location_in_parent); + ::ScreenToClient(GetParent(), &location_in_parent); + parent_update_rect.OffsetRect(location_in_parent); + ::RedrawWindow(GetParent(), parent_update_rect, NULL, + RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); + } else { + RedrawWindow(hwnd_, update_rect, NULL, + RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); + } + // As we were created with a style of WS_CLIPCHILDREN redraw requests may + // result in an empty paint rect in WM_PAINT (this'll happen if a + // child HWND completely contains the update _rect). In such a scenario + // RootView would never get a ProcessPaint and always think it needs to + // be painted (leading to a steady stream of RedrawWindow requests on every + // event). For this reason we tell RootView it doesn't need to paint + // here. + root_view_->ClearPaintRect(); + } +} + +RootView* ContainerWin::GetRootView() { + if (!root_view_.get()) { + // First time the root view is being asked for, create it now. + root_view_.reset(CreateRootView()); + } + return root_view_.get(); +} + +bool ContainerWin::IsVisible() { + return !!::IsWindowVisible(GetHWND()); +} + +bool ContainerWin::IsActive() { + return win_util::IsWindowActive(GetHWND()); +} + +TooltipManager* ContainerWin::GetTooltipManager() { + return tooltip_manager_.get(); +} + + +void ContainerWin::SetLayeredAlpha(BYTE layered_alpha) { + layered_alpha_ = layered_alpha; + +// if (hwnd_) +// UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); +} + +static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { + RootView* root_view = + reinterpret_cast(GetProp(hwnd, kRootViewWindowProperty)); + if (root_view) { + *reinterpret_cast(l_param) = root_view; + return FALSE; // Stop enumerating. + } + return TRUE; // Keep enumerating. +} + +// static +RootView* ContainerWin::FindRootView(HWND hwnd) { + RootView* root_view = + reinterpret_cast(GetProp(hwnd, kRootViewWindowProperty)); + if (root_view) + return root_view; + + // Enumerate all children and check if they have a RootView. + EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast(&root_view)); + + return root_view; +} + +void ContainerWin::Close() { + // Let's hide ourselves right away. + Hide(); + if (close_container_factory_.empty()) { + // And we delay the close so that if we are called from an ATL callback, + // we don't destroy the window before the callback returned (as the caller + // may delete ourselves on destroy and the ATL callback would still + // dereference us when the callback returns). + MessageLoop::current()->PostTask(FROM_HERE, + close_container_factory_.NewRunnableMethod( + &ContainerWin::CloseNow)); + } +} + +void ContainerWin::Hide() { + // 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(NULL, 0, 0, 0, 0, + SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | + SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); +} + +void ContainerWin::CloseNow() { + // We may already have been destroyed if the selection resulted in a tab + // switch which will have reactivated the browser window and closed us, so + // we need to check to see if we're still a window before trying to destroy + // ourself. + if (IsWindow()) + DestroyWindow(); +} + +/////////////////////////////////////////////////////////////////////////////// +// MessageLoop::Observer + +void ContainerWin::WillProcessMessage(const MSG& msg) { +} + +void ContainerWin::DidProcessMessage(const MSG& msg) { + if (root_view_->NeedsPainting(true)) { + PaintNow(root_view_->GetScheduledPaintRect()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// FocusTraversable + +View* ContainerWin::FindNextFocusableView( + View* starting_view, bool reverse, Direction direction, bool dont_loop, + FocusTraversable** focus_traversable, View** focus_traversable_view) { + return root_view_->FindNextFocusableView(starting_view, + reverse, + direction, + dont_loop, + focus_traversable, + focus_traversable_view); +} + +FocusTraversable* ContainerWin::GetFocusTraversableParent() { + // We are a proxy to the root view, so we should be bypassed when traversing + // up and as a result this should not be called. + NOTREACHED(); + return NULL; +} + +void ContainerWin::SetFocusTraversableParent(FocusTraversable* parent) { + root_view_->SetFocusTraversableParent(parent); +} + +View* ContainerWin::GetFocusTraversableParentView() { + // We are a proxy to the root view, so we should be bypassed when traversing + // up and as a result this should not be called. + NOTREACHED(); + return NULL; +} + +void ContainerWin::SetFocusTraversableParentView(View* parent_view) { + root_view_->SetFocusTraversableParentView(parent_view); +} + +/////////////////////////////////////////////////////////////////////////////// +// Message handlers + +void ContainerWin::OnCaptureChanged(HWND hwnd) { + if (has_capture_) { + if (is_mouse_down_) + root_view_->ProcessMouseDragCanceled(); + is_mouse_down_ = false; + has_capture_ = false; + } +} + +void ContainerWin::OnClose() { + // WARNING: this method is NOT called for all ContainerWins. If you need to + // do cleanup code before ContainerWin is destroyed, put it in + // OnDestroy. + + NotificationService::current()->Notify( + NOTIFY_WINDOW_CLOSED, Source(hwnd_), + NotificationService::NoDetails()); + + Close(); +} + +void ContainerWin::OnDestroy() { + root_view_->OnContainerDestroyed(); + + RemoveProp(hwnd_, kRootViewWindowProperty); +} + +LRESULT ContainerWin::OnEraseBkgnd(HDC dc) { + // This is needed for magical win32 flicker ju-ju + return 1; +} + +LRESULT ContainerWin::OnGetObject(UINT uMsg, WPARAM w_param, LPARAM l_param) { + LRESULT reference_result = static_cast(0L); + + // Accessibility readers will send an OBJID_CLIENT message + if (OBJID_CLIENT == l_param) { + // If our MSAA root is already created, reuse that pointer. Otherwise, + // create a new one. + if (!accessibility_root_) { + CComObject* instance = NULL; + + HRESULT hr = CComObject::CreateInstance(&instance); + DCHECK(SUCCEEDED(hr)); + + if (!instance) { + // Return with failure. + return static_cast(0L); + } + + CComPtr accessibility_instance(instance); + + if (!SUCCEEDED(instance->Initialize(root_view_.get()))) { + // Return with failure. + return static_cast(0L); + } + + // All is well, assign the temp instance to the class smart pointer + accessibility_root_.Attach(accessibility_instance.Detach()); + + if (!accessibility_root_) { + // Return with failure. + return static_cast(0L); + } + + // Notify that an instance of IAccessible was allocated for m_hWnd + ::NotifyWinEvent(EVENT_OBJECT_CREATE, GetHWND(), OBJID_CLIENT, + CHILDID_SELF); + } + + // Create a reference to ViewAccessibility that MSAA will marshall + // to the client. + reference_result = LresultFromObject(IID_IAccessible, w_param, + static_cast(accessibility_root_)); + } + return reference_result; +} + +void ContainerWin::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) { + KeyEvent event(Event::ET_KEY_PRESSED, c, rep_cnt, flags); + root_view_->ProcessKeyEvent(event); +} + +void ContainerWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) { + KeyEvent event(Event::ET_KEY_RELEASED, c, rep_cnt, flags); + root_view_->ProcessKeyEvent(event); +} + +void ContainerWin::OnLButtonDown(UINT flags, const CPoint& point) { + ProcessMousePressed(point, flags | MK_LBUTTON, false); +} + +void ContainerWin::OnLButtonUp(UINT flags, const CPoint& point) { + ProcessMouseReleased(point, flags | MK_LBUTTON); +} + +void ContainerWin::OnLButtonDblClk(UINT flags, const CPoint& point) { + ProcessMousePressed(point, flags | MK_LBUTTON, true); +} + +void ContainerWin::OnMButtonDown(UINT flags, const CPoint& point) { + ProcessMousePressed(point, flags | MK_MBUTTON, false); +} + +void ContainerWin::OnMButtonUp(UINT flags, const CPoint& point) { + ProcessMouseReleased(point, flags | MK_MBUTTON); +} + +void ContainerWin::OnMButtonDblClk(UINT flags, const CPoint& point) { + ProcessMousePressed(point, flags | MK_MBUTTON, true); +} + +LRESULT ContainerWin::OnMouseActivate(HWND window, UINT hittest_code, + UINT message) { + SetMsgHandled(FALSE); + return MA_ACTIVATE; +} + +void ContainerWin::OnMouseMove(UINT flags, const CPoint& point) { + ProcessMouseMoved(point, flags, false); +} + +LRESULT ContainerWin::OnMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param) { + ProcessMouseExited(); + return 0; +} + +LRESULT ContainerWin::OnMouseWheel(UINT flags, short distance, + const CPoint& point) { + MouseWheelEvent e(distance, + point.x, + point.y, + Event::ConvertWindowsFlags(flags)); + return root_view_->ProcessMouseWheelEvent(e) ? 0 : 1; +} + +LRESULT ContainerWin::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param) { + tooltip_manager_->OnMouse(msg, w_param, l_param); + SetMsgHandled(FALSE); + return 0; +} + +void ContainerWin::OnNCLButtonDblClk(UINT flags, const CPoint& point) { + SetMsgHandled(FALSE); +} + +void ContainerWin::OnNCLButtonDown(UINT flags, const CPoint& point) { + SetMsgHandled(FALSE); +} + +void ContainerWin::OnNCLButtonUp(UINT flags, const CPoint& point) { + SetMsgHandled(FALSE); +} + +LRESULT ContainerWin::OnNCMouseLeave(UINT uMsg, WPARAM w_param, + LPARAM l_param) { + ProcessMouseExited(); + return 0; +} + +LRESULT ContainerWin::OnNCMouseMove(UINT flags, const CPoint& point) { + // NC points are in screen coordinates. + CPoint temp = point; + MapWindowPoints(HWND_DESKTOP, GetHWND(), &temp, 1); + ProcessMouseMoved(temp, 0, true); + + // We need to process this message to stop Windows from drawing the window + // controls as the mouse moves over the title bar area when the window is + // maximized. + return 0; +} + +void ContainerWin::OnNCRButtonDblClk(UINT flags, const CPoint& point) { + SetMsgHandled(FALSE); +} + +void ContainerWin::OnNCRButtonDown(UINT flags, const CPoint& point) { + SetMsgHandled(FALSE); +} + +void ContainerWin::OnNCRButtonUp(UINT flags, const CPoint& point) { + SetMsgHandled(FALSE); +} + +LRESULT ContainerWin::OnNotify(int w_param, NMHDR* l_param) { + // We can be sent this message before the tooltip manager is created, if a + // subclass overrides OnCreate and creates some kind of Windows control there + // that sends WM_NOTIFY messages. + if (tooltip_manager_.get()) { + bool handled; + LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); + SetMsgHandled(handled); + return result; + } + SetMsgHandled(FALSE); + return 0; +} + +void ContainerWin::OnPaint(HDC dc) { + root_view_->OnPaint(GetHWND()); +} + +void ContainerWin::OnRButtonDown(UINT flags, const CPoint& point) { + ProcessMousePressed(point, flags | MK_RBUTTON, false); +} + +void ContainerWin::OnRButtonUp(UINT flags, const CPoint& point) { + ProcessMouseReleased(point, flags | MK_RBUTTON); +} + +void ContainerWin::OnRButtonDblClk(UINT flags, const CPoint& point) { + ProcessMousePressed(point, flags | MK_RBUTTON, true); +} + +LRESULT ContainerWin::OnSettingChange(UINT msg, WPARAM w_param, + LPARAM l_param) { + if (toplevel_) { + SetMsgHandled(FALSE); + if (w_param != SPI_SETWORKAREA) + return 0; // Return value is effectively ignored in atlwin.h. + + AdjustWindowToFitScreenSize(); + SetMsgHandled(TRUE); + } + // Don't care, overridden by interested subclasses + return 0; +} + +void ContainerWin::OnSize(UINT param, const CSize& size) { + ChangeSize(param, size); +} + +void ContainerWin::OnThemeChanged() { + // Notify NativeTheme. + gfx::NativeTheme::instance()->CloseHandles(); +} + +void ContainerWin::OnFinalMessage(HWND window) { + if (delete_on_destroy_) + delete this; +} + +/////////////////////////////////////////////////////////////////////////////// +// ContainerWin, protected: + +void ContainerWin::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 = GetHWND(); + 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 ContainerWin::ProcessMousePressed(const CPoint& point, UINT flags, + bool dbl_click) { + last_mouse_event_was_move_ = false; + MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, + point.x, + point.y, + (dbl_click ? MouseEvent::EF_IS_DOUBLE_CLICK : 0) | + Event::ConvertWindowsFlags(flags)); + if (root_view_->OnMousePressed(mouse_pressed)) { + is_mouse_down_ = true; + if (!has_capture_) { + SetCapture(); + has_capture_ = true; + current_action_ = FA_FORWARDING; + } + return true; + } + return false; +} + +void ContainerWin::ProcessMouseDragged(const CPoint& point, UINT flags) { + last_mouse_event_was_move_ = false; + MouseEvent mouse_drag(Event::ET_MOUSE_DRAGGED, + point.x, + point.y, + Event::ConvertWindowsFlags(flags)); + root_view_->OnMouseDragged(mouse_drag); +} + +void ContainerWin::ProcessMouseReleased(const CPoint& point, UINT flags) { + last_mouse_event_was_move_ = false; + MouseEvent mouse_up(Event::ET_MOUSE_RELEASED, + point.x, + point.y, + Event::ConvertWindowsFlags(flags)); + // Release the capture first, that way we don't get confused if + // OnMouseReleased blocks. + if (has_capture_ && ReleaseCaptureOnMouseReleased()) { + has_capture_ = false; + current_action_ = FA_NONE; + ReleaseCapture(); + } + is_mouse_down_ = false; + root_view_->OnMouseReleased(mouse_up, false); +} + +void ContainerWin::ProcessMouseMoved(const CPoint &point, UINT flags, + bool is_nonclient) { + // 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(is_nonclient ? TME_NONCLIENT | TME_LEAVE : TME_LEAVE); + if (has_capture_ && is_mouse_down_) { + ProcessMouseDragged(point, flags); + } else { + gfx::Point screen_loc(point); + View::ConvertPointToScreen(root_view_.get(), &screen_loc); + if (last_mouse_event_was_move_ && last_mouse_move_x_ == screen_loc.x() && + last_mouse_move_y_ == screen_loc.y()) { + // Don't generate a mouse event for the same location as the last. + return; + } + last_mouse_move_x_ = screen_loc.x(); + last_mouse_move_y_ = screen_loc.y(); + last_mouse_event_was_move_ = true; + MouseEvent mouse_move(Event::ET_MOUSE_MOVED, + point.x, + point.y, + Event::ConvertWindowsFlags(flags)); + root_view_->OnMouseMoved(mouse_move); + } +} + +void ContainerWin::ProcessMouseExited() { + last_mouse_event_was_move_ = false; + root_view_->ProcessOnMouseExited(); + // Reset our tracking flag so that future mouse movement over this + // ContainerWin results in a new tracking session. + active_mouse_tracking_flags_ = 0; +} + +void ContainerWin::AdjustWindowToFitScreenSize() { + // Desktop size has changed. Make sure we're still on screen. + CRect wr; + GetWindowRect(&wr); + HMONITOR hmon = MonitorFromRect(&wr, MONITOR_DEFAULTTONEAREST); + if (!hmon) { + // No monitor available. + return; + } + + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(hmon, &mi); + gfx::Rect window_rect(wr); + gfx::Rect monitor_rect(mi.rcWork); + gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); + if (!new_window_rect.Equals(window_rect)) { + // New position differs from last, resize window. + ::SetWindowPos(GetHWND(), + 0, + new_window_rect.x(), + new_window_rect.y(), + new_window_rect.width(), + new_window_rect.height(), + SWP_NOACTIVATE | SWP_NOZORDER); + } +} + +void ContainerWin::ChangeSize(UINT size_param, const CSize& size) { + CRect rect; + if (layered_) { + GetWindowRect(&rect); + SizeContents(rect); + } else { + GetClientRect(&rect); + } + + // Resizing changes the size of the view hierarchy and thus forces a + // complete relayout. + root_view_->SetBounds(CRect(CPoint(0,0), rect.Size())); + root_view_->Layout(); + root_view_->SchedulePaint(); + + if (layered_) + PaintNow(rect); +} + +RootView* ContainerWin::CreateRootView() { + return new RootView(this); +} + +/////////////////////////////////////////////////////////////////////////////// +// ContainerWin, private: + +void ContainerWin::SizeContents(const CRect& window_rect) { + contents_.reset(new ChromeCanvas(window_rect.Width(), + window_rect.Height(), + false)); +} + +void ContainerWin::PaintLayeredWindow() { + // Painting monkeys with our cliprect, so we need to save it so that the + // call to UpdateLayeredWindow updates the entire window, not just the + // cliprect. + contents_->save(SkCanvas::kClip_SaveFlag); + CRect dirty_rect = root_view_->GetScheduledPaintRect(); + contents_->ClipRectInt( + dirty_rect.left, dirty_rect.top, dirty_rect.Width(), dirty_rect.Height()); + root_view_->ProcessPaint(contents_.get()); + contents_->restore(); + + UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); +} + +void ContainerWin::UpdateWindowFromContents(HDC dib_dc) { + DCHECK(layered_); + if (can_update_layered_window_) { + CRect wr; + GetWindowRect(&wr); + CSize size(wr.right - wr.left, wr.bottom - wr.top); + CPoint zero_origin(0, 0); + CPoint window_position = wr.TopLeft(); + + BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; + ::UpdateLayeredWindow( + hwnd_, NULL, &window_position, &size, dib_dc, &zero_origin, + RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); + } +} + +std::wstring ContainerWin::GetWindowClassName() { + if (!registered_classes) + registered_classes = new RegisteredClasses(); + ClassInfo class_info(initial_class_style()); + for (RegisteredClasses::iterator i = registered_classes->begin(); + i != registered_classes->end(); ++i) { + if (class_info.Equals(i->info)) + return i->name; + } + + // No class found, need to register one. + static int registered_count = 0; + std::wstring name = + std::wstring(kBaseClassName) + IntToWString(registered_count++); + WNDCLASSEX class_ex; + class_ex.cbSize = sizeof(WNDCLASSEX); + class_ex.style = class_info.style; + class_ex.lpfnWndProc = &ContainerWin::WndProc; + class_ex.cbClsExtra = 0; + class_ex.cbWndExtra = 0; + class_ex.hInstance = NULL; + class_ex.hIcon = LoadIcon(GetModuleHandle(L"chrome.dll"), + MAKEINTRESOURCE(IDR_MAINFRAME)); + class_ex.hCursor = LoadCursor(NULL, IDC_ARROW); + class_ex.hbrBackground = reinterpret_cast(class_info.background + 1); + class_ex.lpszMenuName = NULL; + class_ex.lpszClassName = name.c_str(); + class_ex.hIconSm = class_ex.hIcon; + ATOM atom = RegisterClassEx(&class_ex); + DCHECK(atom); + RegisteredClass registered_class(class_info, name, atom); + registered_classes->push_back(registered_class); + return name; +} + +// static +LRESULT CALLBACK ContainerWin::WndProc(HWND window, UINT message, + WPARAM w_param, LPARAM l_param) { + if (message == WM_NCCREATE) { + CREATESTRUCT* cs = reinterpret_cast(l_param); + ContainerWin* vc = + reinterpret_cast(cs->lpCreateParams); + DCHECK(vc); + win_util::SetWindowUserData(window, vc); + vc->hwnd_ = window; + return TRUE; + } + ContainerWin* vc = reinterpret_cast( + win_util::GetWindowUserData(window)); + if (!vc) + return 0; + LRESULT result = 0; + if (!vc->ProcessWindowMessage(window, message, w_param, l_param, result)) + result = DefWindowProc(window, message, w_param, l_param); + if (message == WM_NCDESTROY) { + vc->hwnd_ = NULL; + vc->OnFinalMessage(window); + } + return result; +} + +} // namespace ChromeViews + diff --git a/chrome/views/container_win.h b/chrome/views/container_win.h new file mode 100644 index 0000000..0a8861a --- /dev/null +++ b/chrome/views/container_win.h @@ -0,0 +1,586 @@ +// Copyright (c) 2006-2008 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 CHROME_VIEWS_CONTAINER_WIN_H_ +#define CHROME_VIEWS_CONTAINER_WIN_H_ + +#include +#include + +#include "base/message_loop.h" +#include "chrome/views/focus_manager.h" +#include "chrome/views/layout_manager.h" +#include "chrome/views/container.h" + +class ChromeCanvas; + +namespace gfx { +class Rect; +} + +namespace ChromeViews { + +class RootView; +class TooltipManager; + +bool SetRootViewForHWND(HWND hwnd, RootView* root_view); +RootView* GetRootViewForHWND(HWND hwnd); + +// A Windows message reflected from other windows. This message is sent +// with the following arguments: +// hWnd - Target window +// uMsg - kReflectedMessage +// wParam - Should be 0 +// lParam - Pointer to MSG struct containing the original message. +static 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. +static const int WM_NCUAHDRAWCAPTION = 0xAE; +static const int WM_NCUAHDRAWFRAME = 0xAF; + +/////////////////////////////////////////////////////////////////////////////// +// +// FillLayout +// A simple LayoutManager that causes the associated view's one child to be +// sized to match the bounds of 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_EVIL_CONSTRUCTORS(FillLayout); +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// ContainerWin +// A container for a ChromeViews hierarchy used to represent anything that can +// be contained within an HWND, e.g. a control, a window, etc. Specializations +// suitable for specific tasks, e.g. top level window, are derived from this. +// +// This Container contains a RootView which owns the hierarchy of ChromeViews +// within it. As long as ChromeViews are part of this tree, they will be +// deleted automatically when the RootView is destroyed. If you remove a view +// from the tree, you are then responsible for cleaning up after it. +// +// Note: We try and keep this API platform-neutral, since to some extent we +// consider this the boundary between the platform and potentially cross +// platform ChromeViews code. In some cases this isn't true, primarily +// because of other code that has not yet been refactored to maintain +// this -- separation. +// +/////////////////////////////////////////////////////////////////////////////// +class ContainerWin : public Container, + public MessageLoopForUI::Observer, + public FocusTraversable, + public AcceleratorTarget { + public: + ContainerWin(); + virtual ~ContainerWin(); + + // Initialize the container with a parent and an initial desired size. + // |contents_view| is the view that will be the single child of RootView + // within this Container. As contents_view is inserted into RootView's tree, + // RootView assumes ownership of this view and cleaning it up. If you remove + // this view, you are responsible for its destruction. If this value is NULL, + // the caller is responsible for populating the RootView, and sizing its + // contents as the window is sized. + // If |has_own_focus_manager| is true, the focus traversal stay confined to + // the window. + void Init(HWND parent, + const gfx::Rect& bounds, + bool has_own_focus_manager); + + // Sets the specified view as the contents of this Container. There can only + // be one contnets view child of this Container's RootView. This view is + // sized to fit the entire size of the RootView. The RootView takes ownership + // of this View, unless it is set as not being parent-owned. + virtual void SetContentsView(View* view); + + // Sets the window styles. This is ONLY used when the window is created. + // In other words, if you invoke this after invoking Init, nothing happens. + void set_window_style(DWORD style) { window_style_ = style; } + DWORD window_style() const { return window_style_; } + + // Sets the extended window styles. See comment about |set_window_style|. + void set_window_ex_style(DWORD style) { window_ex_style_ = style; } + DWORD window_ex_style() const { return window_ex_style_; }; + + // Sets the class style to use. The default is CS_DBLCLKS. + void set_initial_class_style(UINT class_style) { + // We dynamically generate the class name, so don't register it globally! + DCHECK((class_style & CS_GLOBALCLASS) == 0); + class_style_ = class_style; + } + UINT initial_class_style() { return class_style_; } + + void set_delete_on_destroy(bool delete_on_destroy) { + delete_on_destroy_ = delete_on_destroy; + } + + // Sets the initial opacity of a layered window, or updates the window's + // opacity if it is on the screen. + void SetLayeredAlpha(BYTE layered_alpha); + + // Disable Layered Window updates by setting to false. + void set_can_update_layered_window(bool can_update_layered_window) { + can_update_layered_window_ = can_update_layered_window; + } + + // Returns the RootView associated with the specified HWND (if any). + static RootView* FindRootView(HWND hwnd); + + // Closes the window asynchronously by scheduling a task for it. The window + // is destroyed as a result. + // This invokes Hide to hide the window, and schedules a task that + // invokes CloseNow. + virtual void Close(); + + // Hides the window. This does NOT delete the window, it just hides it. + virtual void Hide(); + + // Closes the window synchronously. Note that this should not be called from + // an ATL message callback as it deletes the ContainerWin and ATL will + // dereference it after the callback is processed. + void CloseNow(); + + // All classes registered by ContainerWin start with this name. + static const wchar_t* const kBaseClassName; + + BEGIN_MSG_MAP_EX(0) + // Range handlers must go first! + MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) + MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange) + MESSAGE_RANGE_HANDLER_EX(WM_SETTINGCHANGE, WM_SETTINGCHANGE, OnSettingChange) + + // Reflected message handler + MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage) + + // CustomFrameWindow hacks + MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) + MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) + + // Non-atlcrack.h handlers + MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) + MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnNCMouseLeave) + MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) + + // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. + MSG_WM_ACTIVATE(OnActivate) + 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_ERASEBKGND(OnEraseBkgnd) + MSG_WM_ENDSESSION(OnEndSession) + MSG_WM_EXITMENULOOP(OnExitMenuLoop) + MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) + MSG_WM_HSCROLL(OnHScroll) + MSG_WM_INITMENU(OnInitMenu) + MSG_WM_INITMENUPOPUP(OnInitMenuPopup) + MSG_WM_KEYDOWN(OnKeyDown) + MSG_WM_KEYUP(OnKeyUp) + MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) + MSG_WM_LBUTTONDOWN(OnLButtonDown) + MSG_WM_LBUTTONUP(OnLButtonUp) + MSG_WM_MBUTTONDOWN(OnMButtonDown) + MSG_WM_MBUTTONUP(OnMButtonUp) + MSG_WM_MBUTTONDBLCLK(OnMButtonDblClk) + MSG_WM_MOUSEACTIVATE(OnMouseActivate) + MSG_WM_MOUSEMOVE(OnMouseMove) + MSG_WM_MOUSEWHEEL(OnMouseWheel) + MSG_WM_MOVE(OnMove) + MSG_WM_MOVING(OnMoving) + MSG_WM_NCACTIVATE(OnNCActivate) + MSG_WM_NCCALCSIZE(OnNCCalcSize) + MSG_WM_NCHITTEST(OnNCHitTest) + MSG_WM_NCMOUSEMOVE(OnNCMouseMove) + MSG_WM_NCLBUTTONDBLCLK(OnNCLButtonDblClk) + MSG_WM_NCLBUTTONDOWN(OnNCLButtonDown) + MSG_WM_NCLBUTTONUP(OnNCLButtonUp) + MSG_WM_NCPAINT(OnNCPaint) + MSG_WM_NCRBUTTONDBLCLK(OnNCRButtonDblClk) + MSG_WM_NCRBUTTONDOWN(OnNCRButtonDown) + MSG_WM_NCRBUTTONUP(OnNCRButtonUp) + MSG_WM_NOTIFY(OnNotify) + MSG_WM_PAINT(OnPaint) + MSG_WM_POWERBROADCAST(OnPowerBroadcast) + MSG_WM_RBUTTONDBLCLK(OnRButtonDblClk) + MSG_WM_RBUTTONDOWN(OnRButtonDown) + MSG_WM_RBUTTONUP(OnRButtonUp) + MSG_WM_SETCURSOR(OnSetCursor) + MSG_WM_SETFOCUS(OnSetFocus) + MSG_WM_SETICON(OnSetIcon) + MSG_WM_SETTEXT(OnSetText) + MSG_WM_SIZE(OnSize) + MSG_WM_SYSCOMMAND(OnSysCommand) + MSG_WM_THEMECHANGED(OnThemeChanged) + MSG_WM_VSCROLL(OnVScroll) + MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) + END_MSG_MAP() + + // Overridden from Container: + virtual void GetBounds(CRect *out, bool including_frame) const; + virtual void MoveToFront(bool should_activate); + virtual HWND GetHWND() const; + virtual void PaintNow(const CRect& update_rect); + virtual RootView* GetRootView(); + virtual bool IsVisible(); + virtual bool IsActive(); + virtual TooltipManager* GetTooltipManager(); + + // Overridden from MessageLoop::Observer: + void WillProcessMessage(const MSG& msg); + virtual void DidProcessMessage(const MSG& msg); + + // Overridden from FocusTraversable: + virtual View* FindNextFocusableView(View* starting_view, + bool reverse, + Direction direction, + bool dont_loop, + FocusTraversable** focus_traversable, + View** focus_traversable_view); + virtual FocusTraversable* GetFocusTraversableParent(); + virtual View* GetFocusTraversableParentView(); + + // Overridden from AcceleratorTarget: + virtual bool AcceleratorPressed(const Accelerator& accelerator) { + return false; + } + + void SetFocusTraversableParent(FocusTraversable* parent); + void SetFocusTraversableParentView(View* parent_view); + + virtual bool GetAccelerator(int cmd_id, + ChromeViews::Accelerator* accelerator) { + return false; + } + + BOOL IsWindow() const { + return ::IsWindow(GetHWND()); + } + + BOOL ShowWindow(int command) { + DCHECK(::IsWindow(GetHWND())); + return ::ShowWindow(GetHWND(), command); + } + + HWND SetCapture() { + DCHECK(::IsWindow(GetHWND())); + return ::SetCapture(GetHWND()); + } + + HWND GetParent() const { + return ::GetParent(GetHWND()); + } + + BOOL GetWindowRect(RECT* rect) const { + return ::GetWindowRect(GetHWND(), rect); + } + + BOOL SetWindowPos(HWND hwnd_after, int x, int y, int cx, int cy, UINT flags) { + DCHECK(::IsWindow(GetHWND())); + return ::SetWindowPos(GetHWND(), hwnd_after, x, y, cx, cy, flags); + } + + BOOL IsZoomed() const { + DCHECK(::IsWindow(GetHWND())); + return ::IsZoomed(GetHWND()); + } + + BOOL MoveWindow(int x, int y, int width, int height) { + return MoveWindow(x, y, width, height, TRUE); + } + + BOOL MoveWindow(int x, int y, int width, int height, BOOL repaint) { + DCHECK(::IsWindow(GetHWND())); + return ::MoveWindow(GetHWND(), x, y, width, height, repaint); + } + + int SetWindowRgn(HRGN region, BOOL redraw) { + DCHECK(::IsWindow(GetHWND())); + return ::SetWindowRgn(GetHWND(), region, redraw); + } + + BOOL GetClientRect(RECT* rect) const { + DCHECK(::IsWindow(GetHWND())); + return ::GetClientRect(GetHWND(), rect); + } + + protected: + + // Call close instead of this to Destroy the window. + BOOL DestroyWindow() { + DCHECK(::IsWindow(GetHWND())); + return ::DestroyWindow(GetHWND()); + } + + // Message Handlers + // These are all virtual so that specialized view containers can modify or + // augment processing. + // This list is in _ALPHABETICAL_ order! + // Note: in the base class these functions must do nothing but convert point + // coordinates to client coordinates (if necessary) and forward the + // handling to the appropriate Process* function. This is so that + // subclasses can easily override these methods to do different things + // and have a convenient function to call to get the default behavior. + virtual void OnActivate(UINT action, BOOL minimized, HWND window) { } + virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, + int keystate) { + SetMsgHandled(FALSE); + return 0; + } + virtual void OnCancelMode() {} + virtual void OnCaptureChanged(HWND hwnd); + virtual void OnClose(); + virtual void OnCommand( + UINT notification_code, int command_id, HWND window) { SetMsgHandled(FALSE); } + virtual LRESULT OnCreate(LPCREATESTRUCT create_struct) { return 0; } + // WARNING: If you override this be sure and invoke super, otherwise we'll + // leak a few things. + virtual void OnDestroy(); + virtual void OnEndSession(BOOL ending, UINT logoff) { SetMsgHandled(FALSE); } + virtual void OnExitMenuLoop(BOOL is_track_popup_menu) { SetMsgHandled(FALSE); } + virtual LRESULT OnEraseBkgnd(HDC dc); + virtual void OnGetMinMaxInfo(LPMINMAXINFO mm_info) { } + virtual LRESULT OnGetObject(UINT uMsg, WPARAM w_param, LPARAM l_param); + virtual void OnHScroll(int scroll_type, short position, HWND scrollbar) { + SetMsgHandled(FALSE); + } + virtual void OnInitMenu(HMENU menu) { SetMsgHandled(FALSE); } + virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu) { + SetMsgHandled(FALSE); + } + virtual void OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags); + virtual void OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags); + virtual void OnLButtonDblClk(UINT flags, const CPoint& point); + virtual void OnLButtonDown(UINT flags, const CPoint& point); + virtual void OnLButtonUp(UINT flags, const CPoint& point); + virtual void OnMButtonDblClk(UINT flags, const CPoint& point); + virtual void OnMButtonDown(UINT flags, const CPoint& point); + virtual void OnMButtonUp(UINT flags, const CPoint& point); + virtual LRESULT OnMouseActivate(HWND window, UINT hittest_code, UINT message); + virtual void OnMouseMove(UINT flags, const CPoint& point); + virtual LRESULT OnMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param); + virtual void OnMove(const CPoint& point) { SetMsgHandled(FALSE); } + virtual void OnMoving(UINT param, const LPRECT new_bounds) { } + virtual LRESULT OnMouseWheel(UINT flags, short distance, const CPoint& point); + virtual LRESULT OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param); + virtual LRESULT OnNCActivate(BOOL active) { SetMsgHandled(FALSE); return 0; } + virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param) { SetMsgHandled(FALSE); return 0; } + virtual LRESULT OnNCHitTest(const CPoint& pt) { SetMsgHandled(FALSE); return 0; } + virtual void OnNCLButtonDblClk(UINT flags, const CPoint& point); + virtual void OnNCLButtonDown(UINT flags, const CPoint& point); + virtual void OnNCLButtonUp(UINT flags, const CPoint& point); + virtual LRESULT OnNCMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param); + virtual LRESULT OnNCMouseMove(UINT flags, const CPoint& point); + virtual void OnNCPaint(HRGN rgn) { SetMsgHandled(FALSE); } + virtual void OnNCRButtonDblClk(UINT flags, const CPoint& point); + virtual void OnNCRButtonDown(UINT flags, const CPoint& point); + virtual void OnNCRButtonUp(UINT flags, const CPoint& point); + virtual LRESULT OnNCUAHDrawCaption(UINT msg, + WPARAM w_param, + LPARAM l_param) { + SetMsgHandled(FALSE); + return 0; + } + virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param) { + SetMsgHandled(FALSE); + return 0; + } + virtual LRESULT OnNotify(int w_param, NMHDR* l_param); + virtual void OnPaint(HDC dc); + virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data) { + SetMsgHandled(FALSE); + return 0; + } + virtual void OnRButtonDblClk(UINT flags, const CPoint& point); + virtual void OnRButtonDown(UINT flags, const CPoint& point); + virtual void OnRButtonUp(UINT flags, const CPoint& point); + virtual LRESULT OnReflectedMessage(UINT msg, WPARAM w_param, LPARAM l_param) { + SetMsgHandled(FALSE); + return 0; + } + virtual LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT message) { + SetMsgHandled(FALSE); + return 0; + } + virtual void OnSetFocus(HWND focused_window) { + SetMsgHandled(FALSE); + } + virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon) { + SetMsgHandled(FALSE); + return 0; + } + virtual LRESULT OnSetText(const wchar_t* text) { + SetMsgHandled(FALSE); + return 0; + } + virtual LRESULT OnSettingChange(UINT msg, WPARAM w_param, LPARAM l_param); + 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) { + SetMsgHandled(FALSE); + } + virtual void OnWindowPosChanged(WINDOWPOS* window_pos) { + SetMsgHandled(FALSE); + } + + // deletes this window as it is destroyed, override to provide different + // behavior. + virtual void OnFinalMessage(HWND window); + + // Start tracking all mouse events so that this window gets sent mouse leave + // messages too. |is_nonclient| is true when we should track WM_NCMOUSELEAVE + // messages instead of WM_MOUSELEAVE ones. + void TrackMouseEvents(DWORD mouse_tracking_flags); + + // Actually handle mouse events. These functions are called by subclasses who + // override the message handlers above to do the actual real work of handling + // the event in the View system. + bool ProcessMousePressed(const CPoint& point, UINT flags, bool dbl_click); + void ProcessMouseDragged(const CPoint& point, UINT flags); + void ProcessMouseReleased(const CPoint& point, UINT flags); + void ProcessMouseMoved(const CPoint& point, UINT flags, bool is_nonclient); + void ProcessMouseExited(); + + // Makes sure the window still fits on screen after a settings change message + // from the OS, e.g. a screen resolution change. + virtual void AdjustWindowToFitScreenSize(); + + // Handles re-laying out content in response to a window size change. + virtual void ChangeSize(UINT size_param, const CSize& size); + + // Returns whether capture should be released on mouse release. The default + // is true. + virtual bool ReleaseCaptureOnMouseReleased() { return true; } + + enum FrameAction {FA_NONE = 0, FA_RESIZING, FA_MOVING, FA_FORWARDING}; + + virtual RootView* CreateRootView(); + + // Returns true if this ContainerWin is opaque. + bool opaque() const { return opaque_; } + + // The root of the View hierarchy attached to this window. + scoped_ptr root_view_; + + // Current frame ui action + FrameAction current_action_; + + // Whether or not we have capture the mouse. + bool has_capture_; + + // If true, the mouse is currently down. + bool is_mouse_down_; + + scoped_ptr tooltip_manager_; + + private: + // Resize the bitmap used to contain the contents of the layered window. This + // recreates the entire bitmap. + void SizeContents(const CRect& window_rect); + + // Paint into a DIB and then update the layered window with its contents. + void PaintLayeredWindow(); + + // In layered mode, update the layered window. |dib_dc| represents a handle + // to a device context that contains the contents of the window. + void UpdateWindowFromContents(HDC dib_dc); + + // Invoked from WM_DESTROY. Does appropriate cleanup and invokes OnDestroy + // so that subclasses can do any cleanup they need to. + void OnDestroyImpl(); + + // The windows procedure used by all ContainerWins. + static LRESULT CALLBACK WndProc(HWND window, + UINT message, + WPARAM w_param, + LPARAM l_param); + + // Gets the window class name to use when creating the corresponding HWND. + // If necessary, this registers the window class. + std::wstring GetWindowClassName(); + + // The following factory is used for calls to close the ContainerWin + // instance. + ScopedRunnableMethodFactory close_container_factory_; + + // 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_; + + // Whether or not this is a top level window. + bool toplevel_; + + bool opaque_; + + // Window Styles used when creating the window. + DWORD window_style_; + + // Window Extended Styles used when creating the window. + DWORD window_ex_style_; + + // Style of the class to use. + UINT class_style_; + + // Whether or not this is a layered window. + bool layered_; + + // The default alpha to be applied to the layered window. + BYTE layered_alpha_; + + // A canvas that contains the window contents in the case of a layered + // window. + scoped_ptr contents_; + + // Whether or not the window should delete itself when it is destroyed. + // Set this to false via its setter for stack allocated instances. + bool delete_on_destroy_; + + // True if we are allowed to update the layered window from the DIB backing + // store if necessary. + bool can_update_layered_window_; + + // 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. + + // If true, the last event was a mouse move event. + bool last_mouse_event_was_move_; + + // Coordinates of the last mouse move event, in screen coordinates. + int last_mouse_move_x_; + int last_mouse_move_y_; + + // Instance of accessibility information and handling for MSAA root + CComPtr accessibility_root_; + + // Our hwnd. + HWND hwnd_; +}; + +} // namespace ChromeViews + +#endif // #ifndef CHROME_VIEWS_CONTAINER_WIN_H_ + diff --git a/chrome/views/custom_frame_window.cc b/chrome/views/custom_frame_window.cc index 046210a..9bd9758 100644 --- a/chrome/views/custom_frame_window.cc +++ b/chrome/views/custom_frame_window.cc @@ -525,9 +525,9 @@ gfx::Size DefaultNonClientView::GetPreferredSize() { void DefaultNonClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - // Add our Client View as we are added to the ViewContainer so that if we are + // Add our Client View as we are added to the Container so that if we are // subsequently resized all the parent-child relationships are established. - if (is_add && GetViewContainer() && child == this) + if (is_add && GetContainer() && child == this) AddChildView(container_->client_view()); } @@ -920,7 +920,7 @@ void CustomFrameWindow::SetClientView(ClientView* cv) { DCHECK(cv && !client_view() && GetHWND()); set_client_view(cv); // For a CustomFrameWindow, the non-client view is the root. - HWNDViewContainer::SetContentsView(non_client_view_); + ContainerWin::SetContentsView(non_client_view_); // When the non client view is added to the view hierarchy, it will cause the // client view to be added as well. } @@ -970,7 +970,7 @@ void CustomFrameWindow::SizeWindowToDefault() { } /////////////////////////////////////////////////////////////////////////////// -// CustomFrameWindow, HWNDViewContainer overrides: +// CustomFrameWindow, ContainerWin overrides: void CustomFrameWindow::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { // We handle this message so that we can make sure we interact nicely with diff --git a/chrome/views/custom_frame_window.h b/chrome/views/custom_frame_window.h index b1812a0..fbaff21 100644 --- a/chrome/views/custom_frame_window.h +++ b/chrome/views/custom_frame_window.h @@ -47,7 +47,7 @@ class CustomFrameWindow : public Window { virtual void EnableClose(bool enable); virtual void DisableInactiveRendering(bool disable); - // Overridden from HWNDViewContainer: + // Overridden from ContainerWin: virtual void OnGetMinMaxInfo(MINMAXINFO* minmax_info); virtual void OnInitMenu(HMENU menu); virtual void OnMouseLeave(); diff --git a/chrome/views/dialog_client_view.cc b/chrome/views/dialog_client_view.cc index 2435644..559bc2e 100644 --- a/chrome/views/dialog_client_view.cc +++ b/chrome/views/dialog_client_view.cc @@ -226,7 +226,7 @@ void DialogClientView::ViewHierarchyChanged(bool is_add, View* parent, View* chi if (is_add && child == this) { // Can only add and update the dialog buttons _after_ they are added to the // view hierarchy since they are native controls and require the - // ViewContainer's HWND. + // Container's HWND. ShowDialogButtons(); ClientView::ViewHierarchyChanged(is_add, parent, child); UpdateDialogButtons(); diff --git a/chrome/views/focus_manager.cc b/chrome/views/focus_manager.cc index 8af3542..397a4a8 100644 --- a/chrome/views/focus_manager.cc +++ b/chrome/views/focus_manager.cc @@ -9,10 +9,10 @@ #include "chrome/browser/render_widget_host_view_win.h" #include "chrome/common/notification_types.h" #include "chrome/views/accelerator.h" +#include "chrome/views/container.h" #include "chrome/views/focus_manager.h" #include "chrome/views/root_view.h" #include "chrome/views/view.h" -#include "chrome/views/view_container.h" #include "chrome/views/view_storage.h" // The following keys are used in SetProp/GetProp to associate additional @@ -304,7 +304,7 @@ bool FocusManager::OnKeyDown(HWND window, UINT message, WPARAM wparam, DCHECK((message == WM_KEYDOWN) || (message == WM_SYSKEYDOWN)); if (!IsWindowVisible(root_)) { - // We got a message for a hidden window. Because HWNDViewContainer::Close + // We got a message for a hidden window. Because ContainerWin::Close // hides the window, then destroys it, it it possible to get a message after // we've hidden the window. If we allow the message to be dispatched // chances are we'll crash in some weird place. By returning false we make @@ -425,7 +425,7 @@ bool FocusManager::ContainsView(View* view) { if (!root_view) return false; - ViewContainer* view_container = root_view->GetViewContainer(); + Container* view_container = root_view->GetContainer(); if (!view_container) return false; @@ -457,7 +457,7 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view, View* starting_view = NULL; if (original_starting_view) { // If the starting view has a focus traversable, use it. - // This is the case with HWNDViewContainers for example. + // This is the case with ContainerWins for example. focus_traversable = original_starting_view->GetFocusTraversable(); // Otherwise default to the root view. diff --git a/chrome/views/focus_manager.h b/chrome/views/focus_manager.h index dc80253..e12457f 100644 --- a/chrome/views/focus_manager.h +++ b/chrome/views/focus_manager.h @@ -29,10 +29,10 @@ // This is already done for you if you subclass the NativeControl class or if // you use the HWNDView class. // -// When creating a top window, if it derives from HWNDViewContainer, the +// When creating a top window, if it derives from ContainerWin, the // |has_own_focus_manager| of the Init method lets you specify whether that // window should have its own focus manager (so focus traversal stays confined -// in that window). If you are not deriving from HWNDViewContainer or one of its +// in that window). If you are not deriving from ContainerWin or one of its // derived classes (Window, FramelessWindow, ConstrainedWindow), you must // create a FocusManager when the window is created (it is automatically deleted // when the window is destroyed). @@ -49,7 +49,7 @@ // method SetNextFocusableView(). // // If you are embedding a native view containing a nested RootView (for example -// by adding a NativeControl that contains a HWNDViewContainer as its native +// by adding a NativeControl that contains a ContainerWin as its native // component), then you need to: // - override the View::GetFocusTraversable() method in your outter component. // It should return the RootView of the inner component. This is used when diff --git a/chrome/views/focus_manager_unittest.cc b/chrome/views/focus_manager_unittest.cc index 78d02b4..3eba191 100644 --- a/chrome/views/focus_manager_unittest.cc +++ b/chrome/views/focus_manager_unittest.cc @@ -14,7 +14,7 @@ #include "chrome/views/background.h" #include "chrome/views/border.h" #include "chrome/views/checkbox.h" -#include "chrome/views/hwnd_view_container.h" +#include "chrome/views/container_win.h" #include "chrome/views/label.h" #include "chrome/views/link.h" #include "chrome/views/native_button.h" @@ -114,7 +114,7 @@ class BorderView : public ChromeViews::NativeControl { 0, 0, width(), height(), parent_container, NULL, NULL, NULL); // Create the view container which is a child of the TabControl. - view_container_ = new ChromeViews::HWNDViewContainer(); + view_container_ = new ChromeViews::ContainerWin(); view_container_->Init(tab_control, gfx::Rect(), false); view_container_->SetContentsView(child_); view_container_->SetFocusTraversableParentView(this); @@ -162,12 +162,12 @@ private: } View* child_; - ChromeViews::HWNDViewContainer* view_container_; + ChromeViews::ContainerWin* view_container_; DISALLOW_EVIL_CONSTRUCTORS(BorderView); }; -class TestViewWindow : public ChromeViews::HWNDViewContainer { +class TestViewWindow : public ChromeViews::ContainerWin { public: explicit TestViewWindow(FocusManagerTest* test); ~TestViewWindow() { } @@ -239,7 +239,7 @@ void TestViewWindow::Init() { contents_->SetBackground( ChromeViews::Background::CreateSolidBackground(255, 255, 255)); - HWNDViewContainer::Init(NULL, bounds, true); + ContainerWin::Init(NULL, bounds, true); SetContentsView(contents_); ChromeViews::CheckBox* cb = diff --git a/chrome/views/hwnd_view.cc b/chrome/views/hwnd_view.cc index 3550278..6c66851 100644 --- a/chrome/views/hwnd_view.cc +++ b/chrome/views/hwnd_view.cc @@ -6,9 +6,9 @@ #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/win_util.h" +#include "chrome/views/container.h" #include "chrome/views/focus_manager.h" #include "chrome/views/scroll_view.h" -#include "chrome/views/view_container.h" #include "base/logging.h" namespace ChromeViews { @@ -38,7 +38,7 @@ void HWNDView::Attach(HWND hwnd) { ShowWindow(hwnd_, SW_HIDE); // Need to set the HWND's parent before changing its size to avoid flashing. - ::SetParent(hwnd_, GetViewContainer()->GetHWND()); + ::SetParent(hwnd_, GetContainer()->GetHWND()); UpdateHWNDBounds(); // Register with the focus manager so the associated view is focused when the @@ -66,12 +66,12 @@ void HWNDView::UpdateHWNDBounds() { if (!hwnd_) return; - // Since HWNDs know nothing about the View hierarchy (they are direct children - // of the ViewContainer that hosts our View hierarchy) they need to be - // positioned in the coordinate system of the ViewContainer, not the current + // Since HWNDs know nothing about the View hierarchy (they are direct + // children of the Container that hosts our View hierarchy) they need to be + // positioned in the coordinate system of the Container, not the current // view. gfx::Point top_left; - ConvertPointToViewContainer(this, &top_left); + ConvertPointToContainer(this, &top_left); gfx::Rect vis_bounds = GetVisibleBounds(); bool visible = !vis_bounds.IsEmpty(); @@ -150,7 +150,7 @@ gfx::Size HWNDView::GetPreferredSize() { void HWNDView::ViewHierarchyChanged(bool is_add, View *parent, View *child) { if (hwnd_) { - ViewContainer* vc = GetViewContainer(); + Container* vc = GetContainer(); if (is_add && vc) { HWND parent = ::GetParent(hwnd_); HWND vc_hwnd = vc->GetHWND(); diff --git a/chrome/views/hwnd_view_container.cc b/chrome/views/hwnd_view_container.cc deleted file mode 100644 index 1529085..0000000 --- a/chrome/views/hwnd_view_container.cc +++ /dev/null @@ -1,928 +0,0 @@ -// Copyright (c) 2006-2008 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 "chrome/views/hwnd_view_container.h" - -#include "base/gfx/native_theme.h" -#include "base/string_util.h" -#include "base/win_util.h" -#include "chrome/app/chrome_dll_resource.h" -#include "chrome/common/gfx/chrome_canvas.h" -#include "chrome/common/win_util.h" -#include "chrome/views/aero_tooltip_manager.h" -#include "chrome/views/accessibility/view_accessibility.h" -#include "chrome/views/hwnd_notification_source.h" -#include "chrome/views/root_view.h" - -namespace ChromeViews { - -static const DWORD kWindowDefaultChildStyle = - WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; -static const DWORD kWindowDefaultStyle = WS_OVERLAPPEDWINDOW; -static const DWORD kWindowDefaultExStyle = 0; - -// Property used to link the HWND to its RootView. -static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; - -bool SetRootViewForHWND(HWND hwnd, RootView* root_view) { - return ::SetProp(hwnd, kRootViewWindowProperty, root_view) ? true : false; -} - -RootView* GetRootViewForHWND(HWND hwnd) { - return reinterpret_cast(::GetProp(hwnd, kRootViewWindowProperty)); -} - -// Used to locate the HWNDViewContainer issuing the current Create. Only valid -// for the life of Create. -// -// This obviously assumes we only create HWNDViewContainers from the same -// thread, which is currently the case. -static HWNDViewContainer* instance_issuing_create = NULL; - -/////////////////////////////////////////////////////////////////////////////// -// FillLayout - -FillLayout::FillLayout() { -} - -FillLayout::~FillLayout() { -} - -void FillLayout::Layout(View* host) { - CRect bounds; - host->GetViewContainer()->GetBounds(&bounds, false); - if (host->GetChildViewCount() == 0) - return; - - View* frame_view = host->GetChildViewAt(0); - frame_view->SetBounds(CRect(CPoint(0, 0), bounds.Size())); -} - -gfx::Size FillLayout::GetPreferredSize(View* host) { - DCHECK(host->GetChildViewCount() == 1); - return host->GetChildViewAt(0)->GetPreferredSize(); -} - -/////////////////////////////////////////////////////////////////////////////// -// Window class tracking. - -// static -const wchar_t* const HWNDViewContainer::kBaseClassName = - L"Chrome_HWNDViewContainer_"; - -// Window class information used for registering unique windows. -struct ClassInfo { - UINT style; - HBRUSH background; - - explicit ClassInfo(int style) - : style(style), - background(NULL) {} - - // Compares two ClassInfos. Returns true if all members match. - bool Equals(const ClassInfo& other) { - return (other.style == style && other.background == background); - } -}; - -// Represents a registered window class. -struct RegisteredClass { - RegisteredClass(const ClassInfo& info, - const std::wstring& name, - ATOM atom) - : info(info), - name(name), - atom(atom) { - } - - // Info used to create the class. - ClassInfo info; - - // The name given to the window. - std::wstring name; - - // The ATOM returned from creating the window. - ATOM atom; -}; - -typedef std::list RegisteredClasses; - -// The list of registered classes. -static RegisteredClasses* registered_classes = NULL; - - -/////////////////////////////////////////////////////////////////////////////// -// HWNDViewContainer, public - -HWNDViewContainer::HWNDViewContainer() - : active_mouse_tracking_flags_(0), - has_capture_(false), - current_action_(FA_NONE), - toplevel_(false), - window_style_(0), - window_ex_style_(kWindowDefaultExStyle), - layered_(false), - layered_alpha_(255), - delete_on_destroy_(true), - can_update_layered_window_(true), - last_mouse_event_was_move_(false), - is_mouse_down_(false), - class_style_(CS_DBLCLKS), - hwnd_(NULL), - close_container_factory_(this) { -} - -HWNDViewContainer::~HWNDViewContainer() { - MessageLoopForUI::current()->RemoveObserver(this); -} - -void HWNDViewContainer::Init(HWND parent, - const gfx::Rect& bounds, - bool has_own_focus_manager) { - toplevel_ = parent == NULL; - - if (window_style_ == 0) - window_style_ = toplevel_ ? kWindowDefaultStyle : kWindowDefaultChildStyle; - - // See if the style has been overridden. - opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); - layered_ = !!(window_ex_style_ & WS_EX_LAYERED); - - // Force creation of the RootView if it hasn't been created yet. - GetRootView(); - - // Ensures the parent we have been passed is valid, otherwise CreateWindowEx - // will fail. - if (parent && !::IsWindow(parent)) { - NOTREACHED() << "invalid parent window specified."; - parent = NULL; - } - - hwnd_ = CreateWindowEx(window_ex_style_, GetWindowClassName().c_str(), L"", - window_style_, bounds.x(), bounds.y(), bounds.width(), - bounds.height(), parent, NULL, NULL, this); - DCHECK(hwnd_); - // The window procedure should have set the data for us. - DCHECK(win_util::GetWindowUserData(hwnd_) == this); - - root_view_->OnViewContainerCreated(); - - if (has_own_focus_manager) { - ChromeViews::FocusManager::CreateFocusManager(hwnd_, GetRootView()); - } else { - // Subclass the window so we get the tab key messages when a view with no - // associated native window is focused. - FocusManager::InstallFocusSubclass(hwnd_, NULL); - } - - // Sets the RootView as a property, so the automation can introspect windows. - SetRootViewForHWND(hwnd_, root_view_.get()); - - MessageLoopForUI::current()->AddObserver(this); - - // Windows special DWM window frame requires a special tooltip manager so - // that window controls in Chrome windows don't flicker when you move your - // mouse over them. See comment in aero_tooltip_manager.h. - if (win_util::ShouldUseVistaFrame()) { - tooltip_manager_.reset(new AeroTooltipManager(this, GetHWND())); - } else { - tooltip_manager_.reset(new TooltipManager(this, GetHWND())); - } - - // This message initializes the window so that focus border are shown for - // windows. - ::SendMessage(GetHWND(), - WM_CHANGEUISTATE, - MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), - 0); - - // Bug 964884: detach the IME attached to this window. - // We should attach IMEs only when we need to input CJK strings. - ::ImmAssociateContextEx(GetHWND(), NULL, 0); -} - -void HWNDViewContainer::SetContentsView(View* view) { - DCHECK(view && hwnd_) << "Can't be called until after the HWND is created!"; - // The ContentsView must be set up _after_ the window is created so that its - // ViewContainer pointer is valid. - root_view_->SetLayoutManager(new FillLayout); - if (root_view_->GetChildViewCount() != 0) - root_view_->RemoveAllChildViews(true); - root_view_->AddChildView(view); - - // Manually size the window here to ensure the root view is laid out. - RECT wr; - GetWindowRect(&wr); - ChangeSize(0, CSize(wr.right - wr.left, wr.bottom - wr.top)); -} - -/////////////////////////////////////////////////////////////////////////////// -// ChromeViews::ViewContainer - -void HWNDViewContainer::GetBounds(CRect *out, bool including_frame) const { - if (including_frame) { - GetWindowRect(out); - } else { - GetClientRect(out); - - POINT p = {0, 0}; - ::ClientToScreen(hwnd_, &p); - - out->left += p.x; - out->top += p.y; - out->right += p.x; - out->bottom += p.y; - } -} - -void HWNDViewContainer::MoveToFront(bool should_activate) { - int flags = SWP_NOMOVE | SWP_NOSIZE; - if (!should_activate) { - flags |= SWP_NOACTIVATE; - } - SetWindowPos(HWND_NOTOPMOST, 0, 0, 0, 0, flags); -} - -HWND HWNDViewContainer::GetHWND() const { - return hwnd_; -} - -void HWNDViewContainer::PaintNow(const CRect& update_rect) { - if (layered_) { - PaintLayeredWindow(); - } else if (root_view_->NeedsPainting(false) && IsWindow()) { - if (!opaque_ && GetParent()) { - // We're transparent. Need to force painting to occur from our parent. - CRect parent_update_rect = update_rect; - POINT location_in_parent = { 0, 0 }; - ClientToScreen(hwnd_, &location_in_parent); - ::ScreenToClient(GetParent(), &location_in_parent); - parent_update_rect.OffsetRect(location_in_parent); - ::RedrawWindow(GetParent(), parent_update_rect, NULL, - RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); - } else { - RedrawWindow(hwnd_, update_rect, NULL, - RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); - } - // As we were created with a style of WS_CLIPCHILDREN redraw requests may - // result in an empty paint rect in WM_PAINT (this'll happen if a - // child HWND completely contains the update _rect). In such a scenario - // RootView would never get a ProcessPaint and always think it needs to - // be painted (leading to a steady stream of RedrawWindow requests on every - // event). For this reason we tell RootView it doesn't need to paint - // here. - root_view_->ClearPaintRect(); - } -} - -RootView* HWNDViewContainer::GetRootView() { - if (!root_view_.get()) { - // First time the root view is being asked for, create it now. - root_view_.reset(CreateRootView()); - } - return root_view_.get(); -} - -bool HWNDViewContainer::IsVisible() { - return !!::IsWindowVisible(GetHWND()); -} - -bool HWNDViewContainer::IsActive() { - return win_util::IsWindowActive(GetHWND()); -} - -TooltipManager* HWNDViewContainer::GetTooltipManager() { - return tooltip_manager_.get(); -} - - -void HWNDViewContainer::SetLayeredAlpha(BYTE layered_alpha) { - layered_alpha_ = layered_alpha; - -// if (hwnd_) -// UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); -} - -static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { - RootView* root_view = - reinterpret_cast(GetProp(hwnd, kRootViewWindowProperty)); - if (root_view) { - *reinterpret_cast(l_param) = root_view; - return FALSE; // Stop enumerating. - } - return TRUE; // Keep enumerating. -} - -// static -RootView* HWNDViewContainer::FindRootView(HWND hwnd) { - RootView* root_view = - reinterpret_cast(GetProp(hwnd, kRootViewWindowProperty)); - if (root_view) - return root_view; - - // Enumerate all children and check if they have a RootView. - EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast(&root_view)); - - return root_view; -} - -void HWNDViewContainer::Close() { - // Let's hide ourselves right away. - Hide(); - if (close_container_factory_.empty()) { - // And we delay the close so that if we are called from an ATL callback, - // we don't destroy the window before the callback returned (as the caller - // may delete ourselves on destroy and the ATL callback would still - // dereference us when the callback returns). - MessageLoop::current()->PostTask(FROM_HERE, - close_container_factory_.NewRunnableMethod( - &HWNDViewContainer::CloseNow)); - } -} - -void HWNDViewContainer::Hide() { - // 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(NULL, 0, 0, 0, 0, - SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | - SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); -} - -void HWNDViewContainer::CloseNow() { - // We may already have been destroyed if the selection resulted in a tab - // switch which will have reactivated the browser window and closed us, so - // we need to check to see if we're still a window before trying to destroy - // ourself. - if (IsWindow()) - DestroyWindow(); -} - -/////////////////////////////////////////////////////////////////////////////// -// MessageLoop::Observer - -void HWNDViewContainer::WillProcessMessage(const MSG& msg) { -} - -void HWNDViewContainer::DidProcessMessage(const MSG& msg) { - if (root_view_->NeedsPainting(true)) { - PaintNow(root_view_->GetScheduledPaintRect()); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// FocusTraversable - -View* HWNDViewContainer::FindNextFocusableView( - View* starting_view, bool reverse, Direction direction, bool dont_loop, - FocusTraversable** focus_traversable, View** focus_traversable_view) { - return root_view_->FindNextFocusableView(starting_view, - reverse, - direction, - dont_loop, - focus_traversable, - focus_traversable_view); -} - -FocusTraversable* HWNDViewContainer::GetFocusTraversableParent() { - // We are a proxy to the root view, so we should be bypassed when traversing - // up and as a result this should not be called. - NOTREACHED(); - return NULL; -} - -void HWNDViewContainer::SetFocusTraversableParent(FocusTraversable* parent) { - root_view_->SetFocusTraversableParent(parent); -} - -View* HWNDViewContainer::GetFocusTraversableParentView() { - // We are a proxy to the root view, so we should be bypassed when traversing - // up and as a result this should not be called. - NOTREACHED(); - return NULL; -} - -void HWNDViewContainer::SetFocusTraversableParentView(View* parent_view) { - root_view_->SetFocusTraversableParentView(parent_view); -} - -/////////////////////////////////////////////////////////////////////////////// -// Message handlers - -void HWNDViewContainer::OnCaptureChanged(HWND hwnd) { - if (has_capture_) { - if (is_mouse_down_) - root_view_->ProcessMouseDragCanceled(); - is_mouse_down_ = false; - has_capture_ = false; - } -} - -void HWNDViewContainer::OnClose() { - // WARNING: this method is NOT called for all HWNDViewContainers. If you - // need to do cleanup code before HWNDViewContainer is destroyed, put it - // in OnDestroy. - - NotificationService::current()->Notify( - NOTIFY_WINDOW_CLOSED, Source(hwnd_), - NotificationService::NoDetails()); - - Close(); -} - -void HWNDViewContainer::OnDestroy() { - root_view_->OnViewContainerDestroyed(); - - RemoveProp(hwnd_, kRootViewWindowProperty); -} - -LRESULT HWNDViewContainer::OnEraseBkgnd(HDC dc) { - // This is needed for magical win32 flicker ju-ju - return 1; -} - -LRESULT HWNDViewContainer::OnGetObject(UINT uMsg, WPARAM w_param, - LPARAM l_param) { - LRESULT reference_result = static_cast(0L); - - // Accessibility readers will send an OBJID_CLIENT message - if (OBJID_CLIENT == l_param) { - // If our MSAA root is already created, reuse that pointer. Otherwise, - // create a new one. - if (!accessibility_root_) { - CComObject* instance = NULL; - - HRESULT hr = CComObject::CreateInstance(&instance); - DCHECK(SUCCEEDED(hr)); - - if (!instance) { - // Return with failure. - return static_cast(0L); - } - - CComPtr accessibility_instance(instance); - - if (!SUCCEEDED(instance->Initialize(root_view_.get()))) { - // Return with failure. - return static_cast(0L); - } - - // All is well, assign the temp instance to the class smart pointer - accessibility_root_.Attach(accessibility_instance.Detach()); - - if (!accessibility_root_) { - // Return with failure. - return static_cast(0L); - } - - // Notify that an instance of IAccessible was allocated for m_hWnd - ::NotifyWinEvent(EVENT_OBJECT_CREATE, GetHWND(), OBJID_CLIENT, - CHILDID_SELF); - } - - // Create a reference to ViewAccessibility that MSAA will marshall - // to the client. - reference_result = LresultFromObject(IID_IAccessible, w_param, - static_cast(accessibility_root_)); - } - return reference_result; -} - -void HWNDViewContainer::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) { - KeyEvent event(Event::ET_KEY_PRESSED, c, rep_cnt, flags); - root_view_->ProcessKeyEvent(event); -} - -void HWNDViewContainer::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) { - KeyEvent event(Event::ET_KEY_RELEASED, c, rep_cnt, flags); - root_view_->ProcessKeyEvent(event); -} - -void HWNDViewContainer::OnLButtonDown(UINT flags, const CPoint& point) { - ProcessMousePressed(point, flags | MK_LBUTTON, false); -} - -void HWNDViewContainer::OnLButtonUp(UINT flags, const CPoint& point) { - ProcessMouseReleased(point, flags | MK_LBUTTON); -} - -void HWNDViewContainer::OnLButtonDblClk(UINT flags, const CPoint& point) { - ProcessMousePressed(point, flags | MK_LBUTTON, true); -} - -void HWNDViewContainer::OnMButtonDown(UINT flags, const CPoint& point) { - ProcessMousePressed(point, flags | MK_MBUTTON, false); -} - -void HWNDViewContainer::OnMButtonUp(UINT flags, const CPoint& point) { - ProcessMouseReleased(point, flags | MK_MBUTTON); -} - -void HWNDViewContainer::OnMButtonDblClk(UINT flags, const CPoint& point) { - ProcessMousePressed(point, flags | MK_MBUTTON, true); -} - -LRESULT HWNDViewContainer::OnMouseActivate(HWND window, - UINT hittest_code, - UINT message) { - SetMsgHandled(FALSE); - return MA_ACTIVATE; -} - -void HWNDViewContainer::OnMouseMove(UINT flags, const CPoint& point) { - ProcessMouseMoved(point, flags, false); -} - -LRESULT HWNDViewContainer::OnMouseLeave(UINT uMsg, WPARAM w_param, - LPARAM l_param) { - ProcessMouseExited(); - return 0; -} - -LRESULT HWNDViewContainer::OnMouseWheel(UINT flags, - short distance, - const CPoint& point) { - MouseWheelEvent e(distance, - point.x, - point.y, - Event::ConvertWindowsFlags(flags)); - return root_view_->ProcessMouseWheelEvent(e) ? 0 : 1; -} - -LRESULT HWNDViewContainer::OnMouseRange(UINT msg, - WPARAM w_param, - LPARAM l_param) { - tooltip_manager_->OnMouse(msg, w_param, l_param); - SetMsgHandled(FALSE); - return 0; -} - -void HWNDViewContainer::OnNCLButtonDblClk(UINT flags, const CPoint& point) { - SetMsgHandled(FALSE); -} - -void HWNDViewContainer::OnNCLButtonDown(UINT flags, const CPoint& point) { - SetMsgHandled(FALSE); -} - -void HWNDViewContainer::OnNCLButtonUp(UINT flags, const CPoint& point) { - SetMsgHandled(FALSE); -} - -LRESULT HWNDViewContainer::OnNCMouseLeave(UINT uMsg, - WPARAM w_param, - LPARAM l_param) { - ProcessMouseExited(); - return 0; -} - -LRESULT HWNDViewContainer::OnNCMouseMove(UINT flags, const CPoint& point) { - // NC points are in screen coordinates. - CPoint temp = point; - MapWindowPoints(HWND_DESKTOP, GetHWND(), &temp, 1); - ProcessMouseMoved(temp, 0, true); - - // We need to process this message to stop Windows from drawing the window - // controls as the mouse moves over the title bar area when the window is - // maximized. - return 0; -} - -void HWNDViewContainer::OnNCRButtonDblClk(UINT flags, const CPoint& point) { - SetMsgHandled(FALSE); -} - -void HWNDViewContainer::OnNCRButtonDown(UINT flags, const CPoint& point) { - SetMsgHandled(FALSE); -} - -void HWNDViewContainer::OnNCRButtonUp(UINT flags, const CPoint& point) { - SetMsgHandled(FALSE); -} - -LRESULT HWNDViewContainer::OnNotify(int w_param, NMHDR* l_param) { - // We can be sent this message before the tooltip manager is created, if a - // subclass overrides OnCreate and creates some kind of Windows control there - // that sends WM_NOTIFY messages. - if (tooltip_manager_.get()) { - bool handled; - LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); - SetMsgHandled(handled); - return result; - } - SetMsgHandled(FALSE); - return 0; -} - -void HWNDViewContainer::OnPaint(HDC dc) { - root_view_->OnPaint(GetHWND()); -} - -void HWNDViewContainer::OnRButtonDown(UINT flags, const CPoint& point) { - ProcessMousePressed(point, flags | MK_RBUTTON, false); -} - -void HWNDViewContainer::OnRButtonUp(UINT flags, const CPoint& point) { - ProcessMouseReleased(point, flags | MK_RBUTTON); -} - -void HWNDViewContainer::OnRButtonDblClk(UINT flags, const CPoint& point) { - ProcessMousePressed(point, flags | MK_RBUTTON, true); -} - -LRESULT HWNDViewContainer::OnSettingChange(UINT msg, - WPARAM w_param, - LPARAM l_param) { - if (toplevel_) { - SetMsgHandled(FALSE); - if (w_param != SPI_SETWORKAREA) - return 0; // Return value is effectively ignored in atlwin.h. - - AdjustWindowToFitScreenSize(); - SetMsgHandled(TRUE); - } - // Don't care, overridden by interested subclasses - return 0; -} - -void HWNDViewContainer::OnSize(UINT param, const CSize& size) { - ChangeSize(param, size); -} - -void HWNDViewContainer::OnThemeChanged() { - // Notify NativeTheme. - gfx::NativeTheme::instance()->CloseHandles(); -} - -void HWNDViewContainer::OnFinalMessage(HWND window) { - if (delete_on_destroy_) - delete this; -} - -/////////////////////////////////////////////////////////////////////////////// -// HWNDViewContainer, protected - -void HWNDViewContainer::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 = GetHWND(); - 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 HWNDViewContainer::ProcessMousePressed(const CPoint& point, - UINT flags, - bool dbl_click) { - last_mouse_event_was_move_ = false; - MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, - point.x, - point.y, - (dbl_click ? MouseEvent::EF_IS_DOUBLE_CLICK : 0) | - Event::ConvertWindowsFlags(flags)); - if (root_view_->OnMousePressed(mouse_pressed)) { - is_mouse_down_ = true; - if (!has_capture_) { - SetCapture(); - has_capture_ = true; - current_action_ = FA_FORWARDING; - } - return true; - } - return false; -} - -void HWNDViewContainer::ProcessMouseDragged(const CPoint& point, UINT flags) { - last_mouse_event_was_move_ = false; - MouseEvent mouse_drag(Event::ET_MOUSE_DRAGGED, - point.x, - point.y, - Event::ConvertWindowsFlags(flags)); - root_view_->OnMouseDragged(mouse_drag); -} - -void HWNDViewContainer::ProcessMouseReleased(const CPoint& point, UINT flags) { - last_mouse_event_was_move_ = false; - MouseEvent mouse_up(Event::ET_MOUSE_RELEASED, - point.x, - point.y, - Event::ConvertWindowsFlags(flags)); - // Release the capture first, that way we don't get confused if - // OnMouseReleased blocks. - if (has_capture_ && ReleaseCaptureOnMouseReleased()) { - has_capture_ = false; - current_action_ = FA_NONE; - ReleaseCapture(); - } - is_mouse_down_ = false; - root_view_->OnMouseReleased(mouse_up, false); -} - -void HWNDViewContainer::ProcessMouseMoved(const CPoint &point, UINT flags, - bool is_nonclient) { - // 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(is_nonclient ? TME_NONCLIENT | TME_LEAVE : TME_LEAVE); - if (has_capture_ && is_mouse_down_) { - ProcessMouseDragged(point, flags); - } else { - gfx::Point screen_loc(point); - View::ConvertPointToScreen(root_view_.get(), &screen_loc); - if (last_mouse_event_was_move_ && last_mouse_move_x_ == screen_loc.x() && - last_mouse_move_y_ == screen_loc.y()) { - // Don't generate a mouse event for the same location as the last. - return; - } - last_mouse_move_x_ = screen_loc.x(); - last_mouse_move_y_ = screen_loc.y(); - last_mouse_event_was_move_ = true; - MouseEvent mouse_move(Event::ET_MOUSE_MOVED, - point.x, - point.y, - Event::ConvertWindowsFlags(flags)); - root_view_->OnMouseMoved(mouse_move); - } -} - -void HWNDViewContainer::ProcessMouseExited() { - last_mouse_event_was_move_ = false; - root_view_->ProcessOnMouseExited(); - // Reset our tracking flag so that future mouse movement over this - // HWNDViewContainer results in a new tracking session. - active_mouse_tracking_flags_ = 0; -} - -void HWNDViewContainer::AdjustWindowToFitScreenSize() { - // Desktop size has changed. Make sure we're still on screen. - CRect wr; - GetWindowRect(&wr); - HMONITOR hmon = MonitorFromRect(&wr, MONITOR_DEFAULTTONEAREST); - if (!hmon) { - // No monitor available. - return; - } - - MONITORINFO mi; - mi.cbSize = sizeof(mi); - GetMonitorInfo(hmon, &mi); - gfx::Rect window_rect(wr); - gfx::Rect monitor_rect(mi.rcWork); - gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); - if (!new_window_rect.Equals(window_rect)) { - // New position differs from last, resize window. - ::SetWindowPos(GetHWND(), - 0, - new_window_rect.x(), - new_window_rect.y(), - new_window_rect.width(), - new_window_rect.height(), - SWP_NOACTIVATE | SWP_NOZORDER); - } -} - -void HWNDViewContainer::ChangeSize(UINT size_param, const CSize& size) { - CRect rect; - if (layered_) { - GetWindowRect(&rect); - SizeContents(rect); - } else { - GetClientRect(&rect); - } - - // Resizing changes the size of the view hierarchy and thus forces a - // complete relayout. - root_view_->SetBounds(CRect(CPoint(0,0), rect.Size())); - root_view_->Layout(); - root_view_->SchedulePaint(); - - if (layered_) - PaintNow(rect); -} - -RootView* HWNDViewContainer::CreateRootView() { - return new RootView(this); -} - -/////////////////////////////////////////////////////////////////////////////// -// HWNDViewContainer, private: - -void HWNDViewContainer::SizeContents(const CRect& window_rect) { - contents_.reset(new ChromeCanvas(window_rect.Width(), - window_rect.Height(), - false)); -} - -void HWNDViewContainer::PaintLayeredWindow() { - // Painting monkeys with our cliprect, so we need to save it so that the - // call to UpdateLayeredWindow updates the entire window, not just the - // cliprect. - contents_->save(SkCanvas::kClip_SaveFlag); - CRect dirty_rect = root_view_->GetScheduledPaintRect(); - contents_->ClipRectInt( - dirty_rect.left, dirty_rect.top, dirty_rect.Width(), dirty_rect.Height()); - root_view_->ProcessPaint(contents_.get()); - contents_->restore(); - - UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); -} - -void HWNDViewContainer::UpdateWindowFromContents(HDC dib_dc) { - DCHECK(layered_); - if (can_update_layered_window_) { - CRect wr; - GetWindowRect(&wr); - CSize size(wr.right - wr.left, wr.bottom - wr.top); - CPoint zero_origin(0, 0); - CPoint window_position = wr.TopLeft(); - - BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; - ::UpdateLayeredWindow( - hwnd_, NULL, &window_position, &size, dib_dc, &zero_origin, - RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); - } -} - -std::wstring HWNDViewContainer::GetWindowClassName() { - if (!registered_classes) - registered_classes = new RegisteredClasses(); - ClassInfo class_info(initial_class_style()); - for (RegisteredClasses::iterator i = registered_classes->begin(); - i != registered_classes->end(); ++i) { - if (class_info.Equals(i->info)) - return i->name; - } - - // No class found, need to register one. - static int registered_count = 0; - std::wstring name = - std::wstring(kBaseClassName) + IntToWString(registered_count++); - WNDCLASSEX class_ex; - class_ex.cbSize = sizeof(WNDCLASSEX); - class_ex.style = class_info.style; - class_ex.lpfnWndProc = &HWNDViewContainer::WndProc; - class_ex.cbClsExtra = 0; - class_ex.cbWndExtra = 0; - class_ex.hInstance = NULL; - class_ex.hIcon = LoadIcon(GetModuleHandle(L"chrome.dll"), - MAKEINTRESOURCE(IDR_MAINFRAME)); - class_ex.hCursor = LoadCursor(NULL, IDC_ARROW); - class_ex.hbrBackground = reinterpret_cast(class_info.background + 1); - class_ex.lpszMenuName = NULL; - class_ex.lpszClassName = name.c_str(); - class_ex.hIconSm = class_ex.hIcon; - ATOM atom = RegisterClassEx(&class_ex); - DCHECK(atom); - RegisteredClass registered_class(class_info, name, atom); - registered_classes->push_back(registered_class); - return name; -} - -// static -LRESULT CALLBACK HWNDViewContainer::WndProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param) { - if (message == WM_NCCREATE) { - CREATESTRUCT* cs = reinterpret_cast(l_param); - HWNDViewContainer* vc = - reinterpret_cast(cs->lpCreateParams); - DCHECK(vc); - win_util::SetWindowUserData(window, vc); - vc->hwnd_ = window; - return TRUE; - } - HWNDViewContainer* vc = reinterpret_cast( - win_util::GetWindowUserData(window)); - if (!vc) - return 0; - LRESULT result = 0; - if (!vc->ProcessWindowMessage(window, message, w_param, l_param, result)) - result = DefWindowProc(window, message, w_param, l_param); - if (message == WM_NCDESTROY) { - vc->hwnd_ = NULL; - vc->OnFinalMessage(window); - } - return result; -} - -} // namespace ChromeViews - diff --git a/chrome/views/hwnd_view_container.h b/chrome/views/hwnd_view_container.h deleted file mode 100644 index 2df9622..0000000 --- a/chrome/views/hwnd_view_container.h +++ /dev/null @@ -1,586 +0,0 @@ -// Copyright (c) 2006-2008 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 CHROME_VIEWS_HWND_VIEW_CONTAINER_H_ -#define CHROME_VIEWS_HWND_VIEW_CONTAINER_H_ - -#include -#include - -#include "base/message_loop.h" -#include "chrome/views/focus_manager.h" -#include "chrome/views/layout_manager.h" -#include "chrome/views/view_container.h" - -class ChromeCanvas; - -namespace gfx { -class Rect; -} - -namespace ChromeViews { - -class RootView; -class TooltipManager; - -bool SetRootViewForHWND(HWND hwnd, RootView* root_view); -RootView* GetRootViewForHWND(HWND hwnd); - -// A Windows message reflected from other windows. This message is sent -// with the following arguments: -// hWnd - Target window -// uMsg - kReflectedMessage -// wParam - Should be 0 -// lParam - Pointer to MSG struct containing the original message. -static 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. -static const int WM_NCUAHDRAWCAPTION = 0xAE; -static const int WM_NCUAHDRAWFRAME = 0xAF; - -/////////////////////////////////////////////////////////////////////////////// -// -// FillLayout -// A simple LayoutManager that causes the associated view's one child to be -// sized to match the bounds of 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_EVIL_CONSTRUCTORS(FillLayout); -}; - -/////////////////////////////////////////////////////////////////////////////// -// -// HWNDViewContainer -// A container for a ChromeViews hierarchy used to represent anything that can -// be contained within an HWND, e.g. a control, a window, etc. Specializations -// suitable for specific tasks, e.g. top level window, are derived from this. -// -// This ViewContainer contains a RootView which owns the hierarchy of -// ChromeViews within it. As long as ChromeViews are part of this tree, they -// will be deleted automatically when the RootView is destroyed. If you remove -// a view from the tree, you are then responsible for cleaning up after it. -// -// Note: We try and keep this API platform-neutral, since to some extent we -// consider this the boundary between the platform and potentially cross -// platform ChromeViews code. In some cases this isn't true, primarily -// because of other code that has not yet been refactored to maintain -// this -- separation. -// -/////////////////////////////////////////////////////////////////////////////// -class HWNDViewContainer : public ViewContainer, - public MessageLoopForUI::Observer, - public FocusTraversable, - public AcceleratorTarget { - public: - HWNDViewContainer(); - virtual ~HWNDViewContainer(); - - // Initialize the container with a parent and an initial desired size. - // |contents_view| is the view that will be the single child of RootView - // within this ViewContainer. As contents_view is inserted into RootView's - // tree, RootView assumes ownership of this view and cleaning it up. If you - // remove this view, you are responsible for its destruction. If this value - // is NULL, the caller is responsible for populating the RootView, and sizing - // its contents as the window is sized. - // If |has_own_focus_manager| is true, the focus traversal stay confined to - // the window. - void Init(HWND parent, - const gfx::Rect& bounds, - bool has_own_focus_manager); - - // Sets the specified view as the contents of this HWNDViewContainer. There - // can only be one contnets view child of this ViewContainer's RootView. This - // view is sized to fit the entire size of the RootView. The RootView takes - // ownership of this View, unless it is set as not being parent-owned. - virtual void SetContentsView(View* view); - - // Sets the window styles. This is ONLY used when the window is created. - // In other words, if you invoke this after invoking Init, nothing happens. - void set_window_style(DWORD style) { window_style_ = style; } - DWORD window_style() const { return window_style_; } - - // Sets the extended window styles. See comment about |set_window_style|. - void set_window_ex_style(DWORD style) { window_ex_style_ = style; } - DWORD window_ex_style() const { return window_ex_style_; }; - - // Sets the class style to use. The default is CS_DBLCLKS. - void set_initial_class_style(UINT class_style) { - // We dynamically generate the class name, so don't register it globally! - DCHECK((class_style & CS_GLOBALCLASS) == 0); - class_style_ = class_style; - } - UINT initial_class_style() { return class_style_; } - - void set_delete_on_destroy(bool delete_on_destroy) { - delete_on_destroy_ = delete_on_destroy; - } - - // Sets the initial opacity of a layered window, or updates the window's - // opacity if it is on the screen. - void SetLayeredAlpha(BYTE layered_alpha); - - // Disable Layered Window updates by setting to false. - void set_can_update_layered_window(bool can_update_layered_window) { - can_update_layered_window_ = can_update_layered_window; - } - - // Returns the RootView associated with the specified HWND (if any). - static RootView* FindRootView(HWND hwnd); - - // Closes the window asynchronously by scheduling a task for it. The window - // is destroyed as a result. - // This invokes Hide to hide the window, and schedules a task that - // invokes CloseNow. - virtual void Close(); - - // Hides the window. This does NOT delete the window, it just hides it. - virtual void Hide(); - - // Closes the window synchronously. Note that this should not be called from - // an ATL message callback as it deletes the HWNDDViewContainer and ATL will - // dereference it after the callback is processed. - void CloseNow(); - - // All classes registered by HWNDViewContainer start with this name. - static const wchar_t* const kBaseClassName; - - BEGIN_MSG_MAP_EX(0) - // Range handlers must go first! - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) - MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange) - MESSAGE_RANGE_HANDLER_EX(WM_SETTINGCHANGE, WM_SETTINGCHANGE, OnSettingChange) - - // Reflected message handler - MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage) - - // CustomFrameWindow hacks - MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) - MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) - - // Non-atlcrack.h handlers - MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) - MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnNCMouseLeave) - MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) - - // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. - MSG_WM_ACTIVATE(OnActivate) - 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_ERASEBKGND(OnEraseBkgnd) - MSG_WM_ENDSESSION(OnEndSession) - MSG_WM_EXITMENULOOP(OnExitMenuLoop) - MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) - MSG_WM_HSCROLL(OnHScroll) - MSG_WM_INITMENU(OnInitMenu) - MSG_WM_INITMENUPOPUP(OnInitMenuPopup) - MSG_WM_KEYDOWN(OnKeyDown) - MSG_WM_KEYUP(OnKeyUp) - MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) - MSG_WM_LBUTTONDOWN(OnLButtonDown) - MSG_WM_LBUTTONUP(OnLButtonUp) - MSG_WM_MBUTTONDOWN(OnMButtonDown) - MSG_WM_MBUTTONUP(OnMButtonUp) - MSG_WM_MBUTTONDBLCLK(OnMButtonDblClk) - MSG_WM_MOUSEACTIVATE(OnMouseActivate) - MSG_WM_MOUSEMOVE(OnMouseMove) - MSG_WM_MOUSEWHEEL(OnMouseWheel) - MSG_WM_MOVE(OnMove) - MSG_WM_MOVING(OnMoving) - MSG_WM_NCACTIVATE(OnNCActivate) - MSG_WM_NCCALCSIZE(OnNCCalcSize) - MSG_WM_NCHITTEST(OnNCHitTest) - MSG_WM_NCMOUSEMOVE(OnNCMouseMove) - MSG_WM_NCLBUTTONDBLCLK(OnNCLButtonDblClk) - MSG_WM_NCLBUTTONDOWN(OnNCLButtonDown) - MSG_WM_NCLBUTTONUP(OnNCLButtonUp) - MSG_WM_NCPAINT(OnNCPaint) - MSG_WM_NCRBUTTONDBLCLK(OnNCRButtonDblClk) - MSG_WM_NCRBUTTONDOWN(OnNCRButtonDown) - MSG_WM_NCRBUTTONUP(OnNCRButtonUp) - MSG_WM_NOTIFY(OnNotify) - MSG_WM_PAINT(OnPaint) - MSG_WM_POWERBROADCAST(OnPowerBroadcast) - MSG_WM_RBUTTONDBLCLK(OnRButtonDblClk) - MSG_WM_RBUTTONDOWN(OnRButtonDown) - MSG_WM_RBUTTONUP(OnRButtonUp) - MSG_WM_SETCURSOR(OnSetCursor) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_SETICON(OnSetIcon) - MSG_WM_SETTEXT(OnSetText) - MSG_WM_SIZE(OnSize) - MSG_WM_SYSCOMMAND(OnSysCommand) - MSG_WM_THEMECHANGED(OnThemeChanged) - MSG_WM_VSCROLL(OnVScroll) - MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) - END_MSG_MAP() - - // Overridden from ViewContainer: - virtual void GetBounds(CRect *out, bool including_frame) const; - virtual void MoveToFront(bool should_activate); - virtual HWND GetHWND() const; - virtual void PaintNow(const CRect& update_rect); - virtual RootView* GetRootView(); - virtual bool IsVisible(); - virtual bool IsActive(); - virtual TooltipManager* GetTooltipManager(); - - // Overridden from MessageLoop::Observer: - void WillProcessMessage(const MSG& msg); - virtual void DidProcessMessage(const MSG& msg); - - // Overridden from FocusTraversable: - virtual View* FindNextFocusableView(View* starting_view, - bool reverse, - Direction direction, - bool dont_loop, - FocusTraversable** focus_traversable, - View** focus_traversable_view); - virtual FocusTraversable* GetFocusTraversableParent(); - virtual View* GetFocusTraversableParentView(); - - // Overridden from AcceleratorTarget: - virtual bool AcceleratorPressed(const Accelerator& accelerator) { - return false; - } - - void SetFocusTraversableParent(FocusTraversable* parent); - void SetFocusTraversableParentView(View* parent_view); - - virtual bool GetAccelerator(int cmd_id, - ChromeViews::Accelerator* accelerator) { - return false; - } - - BOOL IsWindow() const { - return ::IsWindow(GetHWND()); - } - - BOOL ShowWindow(int command) { - DCHECK(::IsWindow(GetHWND())); - return ::ShowWindow(GetHWND(), command); - } - - HWND SetCapture() { - DCHECK(::IsWindow(GetHWND())); - return ::SetCapture(GetHWND()); - } - - HWND GetParent() const { - return ::GetParent(GetHWND()); - } - - BOOL GetWindowRect(RECT* rect) const { - return ::GetWindowRect(GetHWND(), rect); - } - - BOOL SetWindowPos(HWND hwnd_after, int x, int y, int cx, int cy, UINT flags) { - DCHECK(::IsWindow(GetHWND())); - return ::SetWindowPos(GetHWND(), hwnd_after, x, y, cx, cy, flags); - } - - BOOL IsZoomed() const { - DCHECK(::IsWindow(GetHWND())); - return ::IsZoomed(GetHWND()); - } - - BOOL MoveWindow(int x, int y, int width, int height) { - return MoveWindow(x, y, width, height, TRUE); - } - - BOOL MoveWindow(int x, int y, int width, int height, BOOL repaint) { - DCHECK(::IsWindow(GetHWND())); - return ::MoveWindow(GetHWND(), x, y, width, height, repaint); - } - - int SetWindowRgn(HRGN region, BOOL redraw) { - DCHECK(::IsWindow(GetHWND())); - return ::SetWindowRgn(GetHWND(), region, redraw); - } - - BOOL GetClientRect(RECT* rect) const { - DCHECK(::IsWindow(GetHWND())); - return ::GetClientRect(GetHWND(), rect); - } - - protected: - - // Call close instead of this to Destroy the window. - BOOL DestroyWindow() { - DCHECK(::IsWindow(GetHWND())); - return ::DestroyWindow(GetHWND()); - } - - // Message Handlers - // These are all virtual so that specialized view containers can modify or - // augment processing. - // This list is in _ALPHABETICAL_ order! - // Note: in the base class these functions must do nothing but convert point - // coordinates to client coordinates (if necessary) and forward the - // handling to the appropriate Process* function. This is so that - // subclasses can easily override these methods to do different things - // and have a convenient function to call to get the default behavior. - virtual void OnActivate(UINT action, BOOL minimized, HWND window) { } - virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, - int keystate) { - SetMsgHandled(FALSE); - return 0; - } - virtual void OnCancelMode() {} - virtual void OnCaptureChanged(HWND hwnd); - virtual void OnClose(); - virtual void OnCommand( - UINT notification_code, int command_id, HWND window) { SetMsgHandled(FALSE); } - virtual LRESULT OnCreate(LPCREATESTRUCT create_struct) { return 0; } - // WARNING: If you override this be sure and invoke super, otherwise we'll - // leak a few things. - virtual void OnDestroy(); - virtual void OnEndSession(BOOL ending, UINT logoff) { SetMsgHandled(FALSE); } - virtual void OnExitMenuLoop(BOOL is_track_popup_menu) { SetMsgHandled(FALSE); } - virtual LRESULT OnEraseBkgnd(HDC dc); - virtual void OnGetMinMaxInfo(LPMINMAXINFO mm_info) { } - virtual LRESULT OnGetObject(UINT uMsg, WPARAM w_param, LPARAM l_param); - virtual void OnHScroll(int scroll_type, short position, HWND scrollbar) { - SetMsgHandled(FALSE); - } - virtual void OnInitMenu(HMENU menu) { SetMsgHandled(FALSE); } - virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu) { - SetMsgHandled(FALSE); - } - virtual void OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags); - virtual void OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags); - virtual void OnLButtonDblClk(UINT flags, const CPoint& point); - virtual void OnLButtonDown(UINT flags, const CPoint& point); - virtual void OnLButtonUp(UINT flags, const CPoint& point); - virtual void OnMButtonDblClk(UINT flags, const CPoint& point); - virtual void OnMButtonDown(UINT flags, const CPoint& point); - virtual void OnMButtonUp(UINT flags, const CPoint& point); - virtual LRESULT OnMouseActivate(HWND window, UINT hittest_code, UINT message); - virtual void OnMouseMove(UINT flags, const CPoint& point); - virtual LRESULT OnMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param); - virtual void OnMove(const CPoint& point) { SetMsgHandled(FALSE); } - virtual void OnMoving(UINT param, const LPRECT new_bounds) { } - virtual LRESULT OnMouseWheel(UINT flags, short distance, const CPoint& point); - virtual LRESULT OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCActivate(BOOL active) { SetMsgHandled(FALSE); return 0; } - virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param) { SetMsgHandled(FALSE); return 0; } - virtual LRESULT OnNCHitTest(const CPoint& pt) { SetMsgHandled(FALSE); return 0; } - virtual void OnNCLButtonDblClk(UINT flags, const CPoint& point); - virtual void OnNCLButtonDown(UINT flags, const CPoint& point); - virtual void OnNCLButtonUp(UINT flags, const CPoint& point); - virtual LRESULT OnNCMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCMouseMove(UINT flags, const CPoint& point); - virtual void OnNCPaint(HRGN rgn) { SetMsgHandled(FALSE); } - virtual void OnNCRButtonDblClk(UINT flags, const CPoint& point); - virtual void OnNCRButtonDown(UINT flags, const CPoint& point); - virtual void OnNCRButtonUp(UINT flags, const CPoint& point); - virtual LRESULT OnNCUAHDrawCaption(UINT msg, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; - } - virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; - } - virtual LRESULT OnNotify(int w_param, NMHDR* l_param); - virtual void OnPaint(HDC dc); - virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data) { - SetMsgHandled(FALSE); - return 0; - } - virtual void OnRButtonDblClk(UINT flags, const CPoint& point); - virtual void OnRButtonDown(UINT flags, const CPoint& point); - virtual void OnRButtonUp(UINT flags, const CPoint& point); - virtual LRESULT OnReflectedMessage(UINT msg, WPARAM w_param, LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; - } - virtual LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT message) { - SetMsgHandled(FALSE); - return 0; - } - virtual void OnSetFocus(HWND focused_window) { - SetMsgHandled(FALSE); - } - virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon) { - SetMsgHandled(FALSE); - return 0; - } - virtual LRESULT OnSetText(const wchar_t* text) { - SetMsgHandled(FALSE); - return 0; - } - virtual LRESULT OnSettingChange(UINT msg, WPARAM w_param, LPARAM l_param); - 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) { - SetMsgHandled(FALSE); - } - virtual void OnWindowPosChanged(WINDOWPOS* window_pos) { - SetMsgHandled(FALSE); - } - - // deletes this window as it is destroyed, override to provide different - // behavior. - virtual void OnFinalMessage(HWND window); - - // Start tracking all mouse events so that this window gets sent mouse leave - // messages too. |is_nonclient| is true when we should track WM_NCMOUSELEAVE - // messages instead of WM_MOUSELEAVE ones. - void TrackMouseEvents(DWORD mouse_tracking_flags); - - // Actually handle mouse events. These functions are called by subclasses who - // override the message handlers above to do the actual real work of handling - // the event in the View system. - bool ProcessMousePressed(const CPoint& point, UINT flags, bool dbl_click); - void ProcessMouseDragged(const CPoint& point, UINT flags); - void ProcessMouseReleased(const CPoint& point, UINT flags); - void ProcessMouseMoved(const CPoint& point, UINT flags, bool is_nonclient); - void ProcessMouseExited(); - - // Makes sure the window still fits on screen after a settings change message - // from the OS, e.g. a screen resolution change. - virtual void AdjustWindowToFitScreenSize(); - - // Handles re-laying out content in response to a window size change. - virtual void ChangeSize(UINT size_param, const CSize& size); - - // Returns whether capture should be released on mouse release. The default - // is true. - virtual bool ReleaseCaptureOnMouseReleased() { return true; } - - enum FrameAction {FA_NONE = 0, FA_RESIZING, FA_MOVING, FA_FORWARDING}; - - virtual RootView* CreateRootView(); - - // Returns true if this HWNDViewContainer is opaque. - bool opaque() const { return opaque_; } - - // The root of the View hierarchy attached to this window. - scoped_ptr root_view_; - - // Current frame ui action - FrameAction current_action_; - - // Whether or not we have capture the mouse. - bool has_capture_; - - // If true, the mouse is currently down. - bool is_mouse_down_; - - scoped_ptr tooltip_manager_; - - private: - // Resize the bitmap used to contain the contents of the layered window. This - // recreates the entire bitmap. - void SizeContents(const CRect& window_rect); - - // Paint into a DIB and then update the layered window with its contents. - void PaintLayeredWindow(); - - // In layered mode, update the layered window. |dib_dc| represents a handle - // to a device context that contains the contents of the window. - void UpdateWindowFromContents(HDC dib_dc); - - // Invoked from WM_DESTROY. Does appropriate cleanup and invokes OnDestroy - // so that subclasses can do any cleanup they need to. - void OnDestroyImpl(); - - // The windows procedure used by all HWNDViewContainers. - static LRESULT CALLBACK WndProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param); - - // Gets the window class name to use when creating the corresponding HWND. - // If necessary, this registers the window class. - std::wstring GetWindowClassName(); - - // The following factory is used for calls to close the HWNDViewContainer - // instance. - ScopedRunnableMethodFactory close_container_factory_; - - // 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_; - - // Whether or not this is a top level window. - bool toplevel_; - - bool opaque_; - - // Window Styles used when creating the window. - DWORD window_style_; - - // Window Extended Styles used when creating the window. - DWORD window_ex_style_; - - // Style of the class to use. - UINT class_style_; - - // Whether or not this is a layered window. - bool layered_; - - // The default alpha to be applied to the layered window. - BYTE layered_alpha_; - - // A canvas that contains the window contents in the case of a layered - // window. - scoped_ptr contents_; - - // Whether or not the window should delete itself when it is destroyed. - // Set this to false via its setter for stack allocated instances. - bool delete_on_destroy_; - - // True if we are allowed to update the layered window from the DIB backing - // store if necessary. - bool can_update_layered_window_; - - // 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. - - // If true, the last event was a mouse move event. - bool last_mouse_event_was_move_; - - // Coordinates of the last mouse move event, in screen coordinates. - int last_mouse_move_x_; - int last_mouse_move_y_; - - // Instance of accessibility information and handling for MSAA root - CComPtr accessibility_root_; - - // Our hwnd. - HWND hwnd_; -}; - -} // namespace ChromeViews - -#endif // #ifndef CHROME_VIEWS_HWND_VIEW_CONTAINER_H_ - diff --git a/chrome/views/label.cc b/chrome/views/label.cc index f6ce601..d918cd5 100644 --- a/chrome/views/label.cc +++ b/chrome/views/label.cc @@ -15,7 +15,7 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/background.h" -#include "chrome/views/view_container.h" +#include "chrome/views/container.h" namespace ChromeViews { diff --git a/chrome/views/menu_button.cc b/chrome/views/menu_button.cc index a7eeb46..847239a 100644 --- a/chrome/views/menu_button.cc +++ b/chrome/views/menu_button.cc @@ -14,10 +14,10 @@ #include "chrome/common/resource_bundle.h" #include "chrome/common/win_util.h" #include "chrome/views/button.h" +#include "chrome/views/container.h" #include "chrome/views/event.h" #include "chrome/views/root_view.h" #include "chrome/views/view_menu_delegate.h" -#include "chrome/views/view_container.h" #include "generated_resources.h" @@ -102,7 +102,7 @@ void MenuButton::Paint(ChromeCanvas* canvas, bool for_drag) { //////////////////////////////////////////////////////////////////////////////// int MenuButton::GetMaximumScreenXCoordinate() { - ViewContainer* vc = GetViewContainer(); + Container* vc = GetContainer(); if (!vc) { NOTREACHED(); @@ -156,7 +156,7 @@ bool MenuButton::Activate() { menu_visible_ = true; menu_delegate_->RunMenu(this, menu_position.ToPOINT(), - GetViewContainer()->GetHWND()); + GetContainer()->GetHWND()); menu_visible_ = false; menu_closed_time_ = Time::Now(); diff --git a/chrome/views/native_control.cc b/chrome/views/native_control.cc index db0403d..5c14c57 100644 --- a/chrome/views/native_control.cc +++ b/chrome/views/native_control.cc @@ -12,8 +12,8 @@ #include "base/win_util.h" #include "chrome/common/l10n_util.h" #include "chrome/views/border.h" +#include "chrome/views/container.h" #include "chrome/views/focus_manager.h" -#include "chrome/views/view_container.h" #include "chrome/views/hwnd_view.h" #include "chrome/views/background.h" #include "base/gfx/native_theme.h" @@ -36,7 +36,7 @@ class NativeControlContainer : public CWindowImplGetViewContainer()->GetHWND()); + Create(parent->GetContainer()->GetHWND()); ::ShowWindow(m_hWnd, SW_SHOW); } @@ -199,14 +199,14 @@ void NativeControl::ValidateNativeControl() { void NativeControl::ViewHierarchyChanged(bool is_add, View *parent, View *child) { - if (is_add && GetViewContainer()) { + if (is_add && GetContainer()) { ValidateNativeControl(); Layout(); } } void NativeControl::Layout() { - if (!container_ && GetViewContainer()) + if (!container_ && GetContainer()) ValidateNativeControl(); if (hwnd_view_) { diff --git a/chrome/views/native_scroll_bar.cc b/chrome/views/native_scroll_bar.cc index 6058646..53c5189 100644 --- a/chrome/views/native_scroll_bar.cc +++ b/chrome/views/native_scroll_bar.cc @@ -11,8 +11,8 @@ #include #include "base/message_loop.h" +#include "chrome/views/container.h" #include "chrome/views/hwnd_view.h" -#include "chrome/views/view_container.h" namespace ChromeViews { @@ -30,7 +30,7 @@ class ScrollBarContainer : public CWindowImplGetViewContainer()->GetHWND()); + Create(parent->GetContainer()->GetHWND()); ::ShowWindow(m_hWnd, SW_SHOW); } @@ -126,7 +126,7 @@ class ScrollBarContainer : public CWindowImplGetViewContainer(); + Container* vc = parent_->GetContainer(); if (vc && vc->GetHWND() != GetFocus()) { parent_->RequestFocus(); } @@ -227,8 +227,8 @@ NativeScrollBar::~NativeScrollBar() { void NativeScrollBar::ViewHierarchyChanged(bool is_add, View *parent, View *child) { - ViewContainer* vc; - if (is_add && (vc = GetViewContainer()) && !sb_view_) { + Container* vc; + if (is_add && (vc = GetContainer()) && !sb_view_) { sb_view_ = new HWNDView(); AddChildView(sb_view_); sb_container_ = new ScrollBarContainer(this); diff --git a/chrome/views/root_view.cc b/chrome/views/root_view.cc index c5b1979..5e7beff 100644 --- a/chrome/views/root_view.cc +++ b/chrome/views/root_view.cc @@ -12,7 +12,7 @@ #include "chrome/common/drag_drop_types.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/views/root_view_drop_target.h" -#include "chrome/views/view_container.h" +#include "chrome/views/container.h" namespace ChromeViews { @@ -51,8 +51,8 @@ const char RootView::kViewClassName[] = "chrome/views/RootView"; // ///////////////////////////////////////////////////////////////////////////// -RootView::RootView(ViewContainer* view_container) - : view_container_(view_container), +RootView::RootView(Container* container) + : container_(container), invalid_rect_(0,0,0,0), mouse_pressed_handler_(NULL), mouse_move_handler_(NULL), @@ -178,7 +178,7 @@ void RootView::PaintNow() { } if (!paint_task_needed_) return; - ViewContainer* vc = GetViewContainer(); + Container* vc = GetContainer(); if (vc) vc->PaintNow(invalid_rect_); } @@ -216,8 +216,8 @@ CRect RootView::GetScheduledPaintRectConstrainedToSize() { // ///////////////////////////////////////////////////////////////////////////// -ViewContainer* RootView::GetViewContainer() const { - return view_container_; +Container* RootView::GetContainer() const { + return container_; } ///////////////////////////////////////////////////////////////////////////// @@ -315,7 +315,7 @@ bool RootView::OnMousePressed(const MouseEvent& e) { mouse_pressed_handler_ = NULL; if (focus_on_mouse_pressed_) { - HWND hwnd = view_container_->GetHWND(); + HWND hwnd = container_->GetHWND(); if (::GetFocus() != hwnd) { ::SetFocus(hwnd); } @@ -331,7 +331,7 @@ bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, // window. (a non explicit mouse handler is automatically // cleared when the control is removed from the hierarchy) if (explicit_mouse_handler_) { - if (mouse_pressed_handler_->GetViewContainer()) { + if (mouse_pressed_handler_->GetContainer()) { *p = l; ConvertPointToScreen(this, p); ConvertPointToView(NULL, mouse_pressed_handler_, p); @@ -463,17 +463,17 @@ void RootView::SetMouseHandler(View *new_mh) { mouse_pressed_handler_ = new_mh; } -void RootView::OnViewContainerCreated() { +void RootView::OnContainerCreated() { DCHECK(!drop_target_.get()); drop_target_ = new RootViewDropTarget(this); } -void RootView::OnViewContainerDestroyed() { +void RootView::OnContainerDestroyed() { if (drop_target_.get()) { - RevokeDragDrop(GetViewContainer()->GetHWND()); + RevokeDragDrop(GetContainer()->GetHWND()); drop_target_ = NULL; } - view_container_ = NULL; + container_ = NULL; } void RootView::ProcessMouseDragCanceled() { @@ -493,7 +493,7 @@ void RootView::FocusView(View* view) { if (view != GetFocusedView()) { FocusManager* focus_manager = GetFocusManager(); DCHECK(focus_manager) << "No Focus Manager for Window " << - (GetViewContainer() ? GetViewContainer()->GetHWND() : 0); + (GetContainer() ? GetContainer()->GetHWND() : 0); if (!focus_manager) return; diff --git a/chrome/views/root_view.h b/chrome/views/root_view.h index 99d744b..14a3977 100644 --- a/chrome/views/root_view.h +++ b/chrome/views/root_view.h @@ -11,7 +11,7 @@ namespace ChromeViews { -class ViewContainer; +class Container; class PaintTask; class RootViewDropTarget; @@ -31,11 +31,11 @@ class FocusListener { // RootView class // // The RootView is the root of a View hierarchy. Its parent is not -// necessarily a ViewContainer, but the ViewContainer's View child is -// always a RootView. +// necessarily a Container, but the Container's View child is always a +// RootView. // // The RootView manages the View hierarchy's interface with the -// ViewContainer, and also maintains the current invalid rect - the region +// Container, and also maintains the current invalid rect - the region // that needs repainting. // ///////////////////////////////////////////////////////////////////////////// @@ -44,7 +44,7 @@ class RootView : public View, public: static const char kViewClassName[]; - explicit RootView(ViewContainer* view_container); + explicit RootView(Container* container); virtual ~RootView(); @@ -71,7 +71,7 @@ class RootView : public View, // returns whether this root view needs to paint as soon as possible. virtual bool NeedsPainting(bool urgent); - // Invoked by the ViewContainer to discover what rectangle should be + // Invoked by the Container to discover what rectangle should be // painted const CRect& GetScheduledPaintRect(); @@ -80,8 +80,8 @@ class RootView : public View, // Tree functions - // Get the ViewContainer that hosts this View. - virtual ViewContainer* GetViewContainer() const; + // Get the Container that hosts this View. + virtual Container* GetContainer() const; // The following event methods are overridden to propagate event to the // control tree @@ -91,19 +91,19 @@ class RootView : public View, virtual void OnMouseMoved(const MouseEvent& e); virtual void SetMouseHandler(View* new_mouse_handler); - // Invoked when the ViewContainers has been fully initialized. - // At the time the constructor is invoked the ViewContainer may not be + // Invoked when the Containers has been fully initialized. + // At the time the constructor is invoked the Container may not be // completely initialized, when this method is invoked, it is. - void OnViewContainerCreated(); + void OnContainerCreated(); - // Invoked prior to the ViewContainer being destroyed. - void OnViewContainerDestroyed(); + // Invoked prior to the Container being destroyed. + void OnContainerDestroyed(); - // Invoked By the ViewContainer if the mouse drag is interrupted by + // Invoked By the Container if the mouse drag is interrupted by // the system. Invokes OnMouseReleased with a value of true for canceled. void ProcessMouseDragCanceled(); - // Invoked by the ViewContainer instance when the mouse moves outside of + // Invoked by the Container instance when the mouse moves outside of // the container bounds virtual void ProcessOnMouseExited(); @@ -167,10 +167,10 @@ class RootView : public View, virtual std::string GetClassName() const; // Clears the region that is schedule to be painted. You nearly never need - // to invoke this. This is primarily intended for ViewContainers. + // to invoke this. This is primarily intended for Containers. void ClearPaintRect(); - // Invoked from the ViewContainer to service a WM_PAINT call. + // Invoked from the Container to service a WM_PAINT call. void OnPaint(HWND hwnd); // Returns the MSAA role of the current view. The role is what assistive @@ -202,7 +202,7 @@ class RootView : public View, DISALLOW_EVIL_CONSTRUCTORS(RootView); // Convert a point to our current mouse handler. Returns false if the - // mouse handler is not connected to a ViewContainer. In that case, the + // mouse handler is not connected to a Container. In that case, the // conversion cannot take place and *p is unchanged bool ConvertPointToMouseHandler(const gfx::Point& l, gfx::Point *p); @@ -267,8 +267,8 @@ class RootView : public View, // The view currently handling enter / exit View* mouse_move_handler_; - // The host ViewContainer - ViewContainer* view_container_; + // The host Container + Container* container_; // The rectangle that should be painted CRect invalid_rect_; diff --git a/chrome/views/root_view_drop_target.cc b/chrome/views/root_view_drop_target.cc index fae3265..a58320c 100644 --- a/chrome/views/root_view_drop_target.cc +++ b/chrome/views/root_view_drop_target.cc @@ -7,13 +7,13 @@ #include "base/gfx/point.h" #include "base/logging.h" #include "chrome/common/drag_drop_types.h" +#include "chrome/views/container.h" #include "chrome/views/root_view.h" -#include "chrome/views/view_container.h" namespace ChromeViews { RootViewDropTarget::RootViewDropTarget(RootView* root_view) - : BaseDropTarget(root_view->GetViewContainer()->GetHWND()), + : BaseDropTarget(root_view->GetContainer()->GetHWND()), root_view_(root_view), target_view_(NULL), deepest_view_(NULL) { diff --git a/chrome/views/tabbed_pane.cc b/chrome/views/tabbed_pane.cc index 473f1db..3d87ca8 100644 --- a/chrome/views/tabbed_pane.cc +++ b/chrome/views/tabbed_pane.cc @@ -16,7 +16,7 @@ #include "chrome/common/stl_util-inl.h" #include "chrome/common/throb_animation.h" #include "chrome/views/background.h" -#include "chrome/views/hwnd_view_container.h" +#include "chrome/views/container_win.h" #include "chrome/views/root_view.h" #include "skia/include/SkColor.h" @@ -166,7 +166,7 @@ HWND TabbedPane::CreateNativeControl(HWND parent_container) { SendMessage(tab_control_, WM_SETFONT, reinterpret_cast(font), FALSE); // Create the view container which is a child of the TabControl. - content_window_ = new HWNDViewContainer(); + content_window_ = new ContainerWin(); content_window_->Init(tab_control_, gfx::Rect(), false); // Explicitly setting the WS_EX_LAYOUTRTL property for the HWND (see above diff --git a/chrome/views/tabbed_pane.h b/chrome/views/tabbed_pane.h index 16cc575..d518a4e 100644 --- a/chrome/views/tabbed_pane.h +++ b/chrome/views/tabbed_pane.h @@ -12,7 +12,7 @@ namespace ChromeViews { // The TabbedPane class is a view that shows tabs. When the user clicks on a // tab, the associated view is displayed. // TODO (jcampan): implement GetPreferredSize(). -class HWNDViewContainer; +class ContainerWin; class TabbedPane : public NativeControl { public: @@ -75,7 +75,7 @@ class TabbedPane : public NativeControl { std::vector tab_views_; // The window displayed in the tab. - HWNDViewContainer* content_window_; + ContainerWin* content_window_; // The listener we notify about tab selection changes. Listener* listener_; diff --git a/chrome/views/table_view.cc b/chrome/views/table_view.cc index 21ada1f..ab33ebf 100644 --- a/chrome/views/table_view.cc +++ b/chrome/views/table_view.cc @@ -15,8 +15,8 @@ #include "chrome/common/gfx/icon_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/win_util.h" +#include "chrome/views/container.h" #include "chrome/views/hwnd_view.h" -#include "chrome/views/view_container.h" #include "SkBitmap.h" #include "SkColorFilter.h" diff --git a/chrome/views/text_button.cc b/chrome/views/text_button.cc index c1631ff..91e2e9808 100644 --- a/chrome/views/text_button.cc +++ b/chrome/views/text_button.cc @@ -10,9 +10,9 @@ #include "chrome/common/throb_animation.h" #include "chrome/common/win_util.h" #include "chrome/views/button.h" +#include "chrome/views/container.h" #include "chrome/views/event.h" #include "chrome/views/view_menu_delegate.h" -#include "chrome/views/view_container.h" #include "generated_resources.h" diff --git a/chrome/views/text_field.cc b/chrome/views/text_field.cc index 6968b2b..2991040 100644 --- a/chrome/views/text_field.cc +++ b/chrome/views/text_field.cc @@ -20,9 +20,9 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/win_util.h" +#include "chrome/views/container.h" #include "chrome/views/hwnd_view.h" #include "chrome/views/menu.h" -#include "chrome/views/view_container.h" #include "generated_resources.h" @@ -248,7 +248,7 @@ TextField::Edit::Edit(TextField* parent, bool draw_border) DWORD ex_style = l10n_util::GetExtendedStyles(); RECT r = {0, 0, parent_->width(), parent_->height()}; - Create(parent_->GetViewContainer()->GetHWND(), r, NULL, style, ex_style); + Create(parent_->GetContainer()->GetHWND(), r, NULL, style, ex_style); // Set up the text_object_model_. CComPtr ole_interface; @@ -800,9 +800,9 @@ TextField::~TextField() { } void TextField::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - ViewContainer* vc; + Container* vc; - if (is_add && (vc = GetViewContainer())) { + if (is_add && (vc = GetContainer())) { // This notification is called from the AddChildView call below. Ignore it. if (native_view_ && !edit_) return; diff --git a/chrome/views/tooltip_manager.cc b/chrome/views/tooltip_manager.cc index e4ea574..aa37cf3 100644 --- a/chrome/views/tooltip_manager.cc +++ b/chrome/views/tooltip_manager.cc @@ -13,7 +13,7 @@ #include "chrome/views/root_view.h" #include "chrome/views/tooltip_manager.h" #include "chrome/views/view.h" -#include "chrome/views/view_container.h" +#include "chrome/views/container.h" namespace ChromeViews { @@ -76,8 +76,8 @@ const std::wstring& TooltipManager::GetLineSeparator() { return *separator; } -TooltipManager::TooltipManager(ViewContainer* container, HWND parent) - : view_container_(container), +TooltipManager::TooltipManager(Container* container, HWND parent) + : container_(container), parent_(parent), last_mouse_x_(-1), last_mouse_y_(-1), @@ -147,7 +147,7 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) { case TTN_GETDISPINFO: { if (last_view_out_of_sync_) { // View under the mouse is out of sync, determine it now. - RootView* root_view = view_container_->GetRootView(); + RootView* root_view = container_->GetRootView(); last_tooltip_view_ = root_view->GetViewForPoint( gfx::Point(last_mouse_x_, last_mouse_y_)); last_view_out_of_sync_ = false; @@ -165,7 +165,7 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) { tooltip_text_.clear(); // Mouse is over a View, ask the View for it's tooltip. gfx::Point view_loc(last_mouse_x_, last_mouse_y_); - View::ConvertPointToView(view_container_->GetRootView(), + View::ConvertPointToView(container_->GetRootView(), last_tooltip_view_, &view_loc); if (last_tooltip_view_->GetTooltipText(view_loc.x(), view_loc.y(), &tooltip_text_) && @@ -194,7 +194,7 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) { if (tooltip_height_ == 0) tooltip_height_ = CalcTooltipHeight(); gfx::Point view_loc(last_mouse_x_, last_mouse_y_); - View::ConvertPointToView(view_container_->GetRootView(), + View::ConvertPointToView(container_->GetRootView(), last_tooltip_view_, &view_loc); if (last_tooltip_view_->GetTooltipTextOrigin( view_loc.x(), view_loc.y(), &text_origin) && @@ -284,7 +284,7 @@ void TooltipManager::TrimTooltipToFit(std::wstring* text, // Determine the available width for the tooltip. gfx::Point screen_loc(position_x, position_y); - View::ConvertPointToScreen(view_container_->GetRootView(), &screen_loc); + View::ConvertPointToScreen(container_->GetRootView(), &screen_loc); gfx::Rect monitor_bounds = win_util::GetMonitorBoundsForRect(gfx::Rect(screen_loc.x(), screen_loc.y(), 0, 0)); @@ -319,7 +319,7 @@ void TooltipManager::TrimTooltipToFit(std::wstring* text, } void TooltipManager::UpdateTooltip(int x, int y) { - RootView* root_view = view_container_->GetRootView(); + RootView* root_view = container_->GetRootView(); View* view = root_view->GetViewForPoint(gfx::Point(x, y)); if (view != last_tooltip_view_) { // NOTE: This *must* be sent regardless of the visibility of the tooltip. @@ -352,7 +352,7 @@ void TooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { if (u_msg >= WM_NCMOUSEMOVE && u_msg <= WM_NCXBUTTONDBLCLK) { // NC message coordinates are in screen coordinates. CRect frame_bounds; - view_container_->GetBounds(&frame_bounds, true); + container_->GetBounds(&frame_bounds, true); x -= frame_bounds.left; y -= frame_bounds.top; } @@ -385,8 +385,8 @@ void TooltipManager::ShowKeyboardTooltip(View* focused_view) { gfx::Point screen_point; focused_view->ConvertPointToScreen(focused_view, &screen_point); gfx::Point relative_point_coordinates; - focused_view->ConvertPointToViewContainer(focused_view, - &relative_point_coordinates); + focused_view->ConvertPointToContainer(focused_view, + &relative_point_coordinates); keyboard_tooltip_hwnd_ = CreateWindowEx( WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), TOOLTIPS_CLASS, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); diff --git a/chrome/views/tooltip_manager.h b/chrome/views/tooltip_manager.h index cb793fa..b48ddeb 100644 --- a/chrome/views/tooltip_manager.h +++ b/chrome/views/tooltip_manager.h @@ -13,11 +13,11 @@ class ChromeFont; namespace ChromeViews { +class Container; class View; -class ViewContainer; // TooltipManager takes care of the wiring to support tooltips for Views. -// This class is intended to be used by ViewContainers. To use this, you must +// This class is intended to be used by Containers. To use this, you must // do the following: // Add the following to your MSG_MAP: // @@ -57,8 +57,8 @@ class TooltipManager { // Returns the separator for lines of text in a tooltip. static const std::wstring& GetLineSeparator(); - // Creates a TooltipManager for the specified ViewContainer and parent window. - TooltipManager(ViewContainer* container, HWND parent); + // Creates a TooltipManager for the specified Container and parent window. + TooltipManager(Container* container, HWND parent); virtual ~TooltipManager(); // Notification that the view hierarchy has changed in some way. @@ -122,7 +122,7 @@ class TooltipManager { void DestroyKeyboardTooltipWindow(HWND window_to_destroy); // Hosting view container. - ViewContainer* view_container_; + Container* container_; // The View the mouse is under. This is null if the mouse isn't under a // View. diff --git a/chrome/views/tree_view.cc b/chrome/views/tree_view.cc index 662f7194..2dca467 100644 --- a/chrome/views/tree_view.cc +++ b/chrome/views/tree_view.cc @@ -13,8 +13,8 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/stl_util-inl.h" +#include "chrome/views/container.h" #include "chrome/views/focus_manager.h" -#include "chrome/views/view_container.h" namespace ChromeViews { @@ -411,7 +411,7 @@ bool TreeView::OnKeyDown(int virtual_key_code) { } return true; } else if (virtual_key_code == VK_RETURN && !process_enter_) { - ViewContainer* vc = GetViewContainer(); + Container* vc = GetContainer(); DCHECK(vc); FocusManager* fm = FocusManager::GetFocusManager(vc->GetHWND()); DCHECK(fm); diff --git a/chrome/views/view.cc b/chrome/views/view.cc index cbb1b25..6b8f53e 100644 --- a/chrome/views/view.cc +++ b/chrome/views/view.cc @@ -22,10 +22,10 @@ #include "chrome/views/accessibility/accessible_wrapper.h" #include "chrome/views/background.h" #include "chrome/views/border.h" +#include "chrome/views/container.h" #include "chrome/views/layout_manager.h" #include "chrome/views/root_view.h" #include "chrome/views/tooltip_manager.h" -#include "chrome/views/view_container.h" #include "SkShader.h" namespace ChromeViews { @@ -323,7 +323,7 @@ void View::SetFocusable(bool focusable) { } FocusManager* View::GetFocusManager() { - ViewContainer* container = GetViewContainer(); + Container* container = GetContainer(); if (!container) return NULL; @@ -803,14 +803,14 @@ View* View::GetViewForPoint(const gfx::Point& point, return this; } -ViewContainer* View::GetViewContainer() const { +Container* View::GetContainer() const { // The root view holds a reference to this view hierarchy's container. - return parent_ ? parent_->GetViewContainer() : NULL; + return parent_ ? parent_->GetContainer() : NULL; } // Get the containing RootView RootView* View::GetRootView() { - ViewContainer* vc = GetViewContainer(); + Container* vc = GetContainer(); if (vc) { return vc->GetRootView(); } else { @@ -1319,7 +1319,7 @@ void View::ConvertPointToView(View* src, View* dst, gfx::Point* point, // If src is NULL, sp is in the screen coordinate system if (src == NULL) { - ViewContainer* vc = dst->GetViewContainer(); + Container* vc = dst->GetContainer(); if (vc) { CRect b; vc->GetBounds(&b, false); @@ -1330,7 +1330,7 @@ void View::ConvertPointToView(View* src, View* dst, gfx::Point* point, } // static -void View::ConvertPointToViewContainer(View* src, gfx::Point* p) { +void View::ConvertPointToContainer(View* src, gfx::Point* p) { DCHECK(src); DCHECK(p); @@ -1344,9 +1344,9 @@ void View::ConvertPointToViewContainer(View* src, gfx::Point* p) { } // static -void View::ConvertPointFromViewContainer(View *source, gfx::Point* p) { +void View::ConvertPointFromContainer(View *source, gfx::Point* p) { gfx::Point t; - ConvertPointToViewContainer(source, &t); + ConvertPointToContainer(source, &t); p->SetPoint(p->x() - t.x(), p->y() - t.y()); } @@ -1356,9 +1356,9 @@ void View::ConvertPointToScreen(View* src, gfx::Point* p) { DCHECK(p); // If the view is not connected to a tree, there's nothing we can do. - ViewContainer* vc = src->GetViewContainer(); + Container* vc = src->GetContainer(); if (vc) { - ConvertPointToViewContainer(src, p); + ConvertPointToContainer(src, p); CRect r; vc->GetBounds(&r, false); p->SetPoint(p->x() + r.left, p->y() + r.top); @@ -1531,7 +1531,7 @@ void View::Focus() { // messages. FocusManager* focus_manager = GetFocusManager(); if (focus_manager) - focus_manager->FocusHWND(GetRootView()->GetViewContainer()->GetHWND()); + focus_manager->FocusHWND(GetRootView()->GetContainer()->GetHWND()); } bool View::CanProcessTabKeyEvents() { @@ -1548,13 +1548,13 @@ bool View::GetTooltipTextOrigin(int x, int y, CPoint* loc) { } void View::TooltipTextChanged() { - ViewContainer* view_container = GetViewContainer(); + Container* view_container = GetContainer(); if (view_container != NULL && view_container->GetTooltipManager()) view_container->GetTooltipManager()->TooltipTextChanged(this); } void View::UpdateTooltip() { - ViewContainer* view_container = GetViewContainer(); + Container* view_container = GetContainer(); if (view_container != NULL && view_container->GetTooltipManager()) view_container->GetTooltipManager()->UpdateTooltip(); } @@ -1587,8 +1587,8 @@ gfx::Rect View::GetVisibleBounds() { ancestor_bounds.SetRect(0, 0, ancestor->width(), ancestor->height()); vis_bounds = vis_bounds.Intersect(ancestor_bounds); - } else if (!view->GetViewContainer()) { - // If the view has no ViewContainer, we're not visible. Return an empty + } else if (!view->GetContainer()) { + // If the view has no Container, we're not visible. Return an empty // rect. return gfx::Rect(); } diff --git a/chrome/views/view.h b/chrome/views/view.h index 18314b0..2d0f21e 100644 --- a/chrome/views/view.h +++ b/chrome/views/view.h @@ -31,13 +31,13 @@ namespace ChromeViews { class Background; class Border; +class Container; class FocusManager; class FocusTraversable; class LayoutManager; class RestoreFocusTask; class RootView; class ScrollView; -class ViewContainer; // ContextMenuController is responsible for showing the context menu for a // View. To use a ContextMenuController invoke SetContextMenuController on a @@ -430,8 +430,8 @@ class View : public AcceleratorTarget { // Get the child View at the specified point. virtual View* GetViewForPoint(const gfx::Point& point); - // Get the containing ViewContainer - virtual ViewContainer* GetViewContainer() const; + // Get the Container that hosts this View, if any. + virtual Container* GetContainer() const; // Get the containing RootView virtual RootView* GetRootView(); @@ -503,7 +503,7 @@ class View : public AcceleratorTarget { // Convenience method to retrieve the FocusManager associated with the // container window that contains this view. This can return NULL if this - // view is not part of a view hierarchy with a ViewContainer. + // view is not part of a view hierarchy with a Container. virtual FocusManager* GetFocusManager(); // Sets a keyboard accelerator for that view. When the user presses the @@ -675,13 +675,13 @@ class View : public AcceleratorTarget { gfx::Point* point); // Convert a point from the coordinate system of a View to that of the - // ViewContainer. This is useful for example when sizing HWND children - // of the ViewContainer that don't know about the View hierarchy and need - // to be placed relative to the ViewContainer that is their parent. - static void ConvertPointToViewContainer(View* src, gfx::Point* point); + // Container. This is useful for example when sizing HWND children of the + // Container that don't know about the View hierarchy and need to be placed + // relative to the Container that is their parent. + static void ConvertPointToContainer(View* src, gfx::Point* point); - // Convert a point from a view ViewContainer to a View dest - static void ConvertPointFromViewContainer(View *dest, gfx::Point* p); + // Convert a point from a view Container to a View dest + static void ConvertPointFromContainer(View *dest, gfx::Point* p); // Convert a point from the coordinate system of a View to that of the // screen. This is useful for example when placing popup windows. @@ -1168,7 +1168,7 @@ class View : public AcceleratorTarget { gfx::Point* point, bool try_other_direction); - // Propagates UpdateTooltip() to the TooltipManager for the ViewContainer. + // Propagates UpdateTooltip() to the TooltipManager for the Container. // This must be invoked any time the View hierarchy changes in such a way // the view under the mouse differs. For example, if the bounds of a View is // changed, this is invoked. Similarly, as Views are added/removed, this diff --git a/chrome/views/view_container.h b/chrome/views/view_container.h deleted file mode 100644 index 52ef668..0000000 --- a/chrome/views/view_container.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2006-2008 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 CHROME_VIEWS_VIEW_CONTAINER_H_ -#define CHROME_VIEWS_VIEW_CONTAINER_H_ - -// TODO(maruel): Remove once HWND is abstracted. -#include - -// TODO(maruel): Remove once gfx::Rect is used instead. -namespace WTL { -class CRect; -} -using WTL::CRect; - -namespace ChromeViews { - -class RootView; -class TooltipManager; -class Accelerator; - -///////////////////////////////////////////////////////////////////////////// -// -// ViewContainer class -// -// ViewContainer is an abstract class that defines the API that should -// be implemented by a CWindow / HWND implementation in order to host a view -// hierarchy. -// -// ViewContainer wraps a hierarchy of View objects (see view.h) that -// implement painting and flexible layout within the bounds of the -// ViewContainer's window. -// -// The ViewContainer is responsible for handling various system events and -// forwarding them to the appropriate view. -// -///////////////////////////////////////////////////////////////////////////// - -class ViewContainer { - public: - virtual ~ViewContainer() { } - - // Returns the bounds of this container in the screen coordinate system. - // If the receiving view container is a frame which is larger than its - // client area, this method returns the client area if including_frame is - // false and the frame bounds otherwise. If the receiving view container - // is not a frame, including_frame is ignored. - virtual void GetBounds(CRect *out, bool including_frame) const = 0; - - // Moves this view container to the front of the Z-Order - // If should_activate is TRUE, the window should also become the active - // window - virtual void MoveToFront(bool should_activate) = 0; - - // Returns the Window HWND associated with this container - virtual HWND GetHWND() const = 0; - - // Forces a paint of a specified rectangle immediately. - virtual void PaintNow(const CRect& update_rect) = 0; - - // Returns the RootView contained by this container - virtual RootView* GetRootView() = 0; - - // Returns whether the view container is visible to the user - virtual bool IsVisible() = 0; - - // Returns whether the view container is the currently active window. - virtual bool IsActive() = 0; - - // Returns the TooltipManager for this ViewContainer. If this ViewContainer - // does not support tooltips, NULL is returned. - virtual TooltipManager* GetTooltipManager() { - return NULL; - } - - // Returns the accelerator given a command id. Returns false if there is - // no accelerator associated with a given id, which is a common condition. - virtual bool GetAccelerator(int cmd_id, - Accelerator* accelerator) = 0; -}; - -} // namespace ChromeViews - -#endif // CHROME_VIEWS_VIEW_CONTAINER_H_ - diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc index 91c556c..38df3bd 100644 --- a/chrome/views/view_unittest.cc +++ b/chrome/views/view_unittest.cc @@ -281,7 +281,7 @@ TEST_F(ViewTest, MouseEvent) { TestView* v2 = new TestView(); v2->SetBounds (100, 100, 100, 100); - ChromeViews::HWNDViewContainer window; + ChromeViews::ContainerWin window; window.set_delete_on_destroy(false); window.set_window_style(WS_OVERLAPPEDWINDOW); window.Init(NULL, gfx::Rect(50, 50, 650, 650), false); @@ -355,7 +355,7 @@ TEST_F(ViewTest, Painting) { RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); bool empty_paint = paint_window.empty_paint(); - ChromeViews::HWNDViewContainer window; + ChromeViews::ContainerWin window; window.set_delete_on_destroy(false); window.set_window_style(WS_OVERLAPPEDWINDOW); window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL); @@ -442,7 +442,7 @@ TEST_F(ViewTest, RemoveNotification) { NotificationService::current()->AddObserver( observer.get(), NOTIFY_VIEW_REMOVED, NotificationService::AllSources()); - ChromeViews::HWNDViewContainer* window = new ChromeViews::HWNDViewContainer; + ChromeViews::ContainerWin* window = new ChromeViews::ContainerWin; ChromeViews::RootView* root_view = window->GetRootView(); View* v1 = new View; @@ -546,7 +546,7 @@ gfx::Point ConvertPointToView(ChromeViews::View* view, const gfx::Point& p) { } TEST_F(ViewTest, HitTestMasks) { - ChromeViews::HWNDViewContainer window; + ChromeViews::ContainerWin window; ChromeViews::RootView* root_view = window.GetRootView(); root_view->SetBounds(0, 0, 500, 500); diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj index ecb5048..0a6ef96 100644 --- a/chrome/views/views.vcproj +++ b/chrome/views/views.vcproj @@ -258,6 +258,18 @@ > + + + + + + @@ -346,14 +358,6 @@ > - - - - @@ -598,10 +602,6 @@ > - - diff --git a/chrome/views/window.cc b/chrome/views/window.cc index 78df878..4c9de42 100644 --- a/chrome/views/window.cc +++ b/chrome/views/window.cc @@ -117,7 +117,7 @@ void Window::Close() { if (client_view_->CanClose()) { SaveWindowPosition(); RestoreEnabledIfNecessary(); - HWNDViewContainer::Close(); + ContainerWin::Close(); // If the user activates another app after opening us, then comes back and // closes us, we want our owner to gain activation. But only if the owner // is visible. If we don't manually force that here, the other app will @@ -259,7 +259,7 @@ gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, // Window, protected: Window::Window(WindowDelegate* window_delegate) - : HWNDViewContainer(), + : ContainerWin(), focus_on_creation_(true), window_delegate_(window_delegate), non_client_view_(NULL), @@ -286,7 +286,7 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) { // return NULL. owning_hwnd_ = parent; // We call this after initializing our members since our implementations of - // assorted HWNDViewContainer functions may be called during initialization. + // assorted ContainerWin functions may be called during initialization. is_modal_ = window_delegate_->IsModal(); if (is_modal_) BecomeModal(); @@ -297,7 +297,7 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) { if (window_ex_style() == 0) set_window_ex_style(CalculateWindowExStyle()); - HWNDViewContainer::Init(parent, bounds, true); + ContainerWin::Init(parent, bounds, true); win_util::SetWindowUserData(GetHWND(), this); std::wstring window_title = window_delegate_->GetWindowTitle(); @@ -318,9 +318,9 @@ void Window::SetClientView(ClientView* client_view) { client_view_ = client_view; if (non_client_view_) { // This will trigger the ClientView to be added by the non-client view. - HWNDViewContainer::SetContentsView(non_client_view_); + ContainerWin::SetContentsView(non_client_view_); } else { - HWNDViewContainer::SetContentsView(client_view_); + ContainerWin::SetContentsView(client_view_); } } @@ -352,7 +352,7 @@ void Window::RunSystemMenu(const CPoint& point) { } /////////////////////////////////////////////////////////////////////////////// -// Window, HWNDViewContainer overrides: +// Window, ContainerWin overrides: void Window::OnActivate(UINT action, BOOL minimized, HWND window) { if (action == WA_INACTIVE) @@ -363,17 +363,15 @@ LRESULT Window::OnAppCommand(HWND window, short app_command, WORD device, int keystate) { // We treat APPCOMMAND ids as an extension of our command namespace, and just // let the delegate figure out what to do... - if (!window_delegate_->ExecuteWindowsCommand(app_command)) { - return HWNDViewContainer::OnAppCommand(window, app_command, device, - keystate); - } + if (!window_delegate_->ExecuteWindowsCommand(app_command)) + return ContainerWin::OnAppCommand(window, app_command, device, keystate); return 0; } void Window::OnCommand(UINT notification_code, int command_id, HWND window) { if (!window_delegate_->ExecuteWindowsCommand(command_id)) - HWNDViewContainer::OnCommand(notification_code, command_id, window); + ContainerWin::OnCommand(notification_code, command_id, window); } void Window::OnDestroy() { @@ -382,7 +380,7 @@ void Window::OnDestroy() { window_delegate_ = NULL; } RestoreEnabledIfNecessary(); - HWNDViewContainer::OnDestroy(); + ContainerWin::OnDestroy(); } LRESULT Window::OnEraseBkgnd(HDC dc) { @@ -396,7 +394,7 @@ LRESULT Window::OnNCActivate(BOOL active) { return DefWindowProc(GetHWND(), WM_NCACTIVATE, TRUE, 0); } // Otherwise just do the default thing. - return HWNDViewContainer::OnNCActivate(active); + return ContainerWin::OnNCActivate(active); } LRESULT Window::OnNCHitTest(const CPoint& point) { @@ -422,14 +420,14 @@ LRESULT Window::OnNCHitTest(const CPoint& point) { void Window::OnNCLButtonDown(UINT ht_component, const CPoint& point) { if (non_client_view_ && ht_component == HTSYSMENU) RunSystemMenu(non_client_view_->GetSystemMenuPoint()); - HWNDViewContainer::OnNCLButtonDown(ht_component, point); + ContainerWin::OnNCLButtonDown(ht_component, point); } void Window::OnNCRButtonDown(UINT ht_component, const CPoint& point) { if (ht_component == HTCAPTION || ht_component == HTSYSMENU) { RunSystemMenu(point); } else { - HWNDViewContainer::OnNCRButtonDown(ht_component, point); + ContainerWin::OnNCRButtonDown(ht_component, point); } } diff --git a/chrome/views/window.h b/chrome/views/window.h index fcf3e49..cfb0b88 100644 --- a/chrome/views/window.h +++ b/chrome/views/window.h @@ -5,7 +5,7 @@ #ifndef CHROME_VIEWS_WINDOW_H__ #define CHROME_VIEWS_WINDOW_H__ -#include "chrome/views/hwnd_view_container.h" +#include "chrome/views/container_win.h" namespace gfx { class Size; @@ -22,15 +22,15 @@ class Client; class NonClientView; class WindowDelegate; -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // // Window // -// A Window is a HWNDViewContainer that has a caption and a border. The frame -// is rendered by the operating system. +// A Window is a ContainerWin that has a caption and a border. The frame is +// rendered by the operating system. // -//////////////////////////////////////////////////////////////////////////////// -class Window : public HWNDViewContainer { +/////////////////////////////////////////////////////////////////////////////// +class Window : public ContainerWin { public: virtual ~Window(); @@ -156,7 +156,7 @@ class Window : public HWNDViewContainer { // Shows the system menu at the specified screen point. void RunSystemMenu(const CPoint& point); - // Overridden from HWNDViewContainer: + // Overridden from ContainerWin: virtual void OnActivate(UINT action, BOOL minimized, HWND window); virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, int keystate); -- cgit v1.1