Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: views/widget/widget_win.h

Issue 165022: Factor out window creation into base::WindowImpl. This class will be used in... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/window_impl.cc ('k') | views/widget/widget_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef VIEWS_WIDGET_WIDGET_WIN_H_ 5 #ifndef VIEWS_WIDGET_WIDGET_WIN_H_
6 #define VIEWS_WIDGET_WIDGET_WIN_H_ 6 #define VIEWS_WIDGET_WIDGET_WIN_H_
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlapp.h> 9 #include <atlapp.h>
10 #include <atlcrack.h> 10 #include <atlcrack.h>
11 #include <atlmisc.h> 11 #include <atlmisc.h>
12 12
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/system_monitor.h" 14 #include "base/system_monitor.h"
15 #include "base/window_impl.h"
15 #include "views/focus/focus_manager.h" 16 #include "views/focus/focus_manager.h"
16 #include "views/layout_manager.h" 17 #include "views/layout_manager.h"
17 #include "views/widget/widget.h" 18 #include "views/widget/widget.h"
18 19
19 namespace gfx { 20 namespace gfx {
20 class Canvas; 21 class Canvas;
21 class Rect; 22 class Rect;
22 } 23 }
23 24
24 namespace views { 25 namespace views {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // A Widget for a views hierarchy used to represent anything that can be 57 // A Widget for a views hierarchy used to represent anything that can be
57 // contained within an HWND, e.g. a control, a window, etc. Specializations 58 // contained within an HWND, e.g. a control, a window, etc. Specializations
58 // suitable for specific tasks, e.g. top level window, are derived from this. 59 // suitable for specific tasks, e.g. top level window, are derived from this.
59 // 60 //
60 // This Widget contains a RootView which owns the hierarchy of views within it. 61 // This Widget contains a RootView which owns the hierarchy of views within it.
61 // As long as views are part of this tree, they will be deleted automatically 62 // As long as views are part of this tree, they will be deleted automatically
62 // when the RootView is destroyed. If you remove a view from the tree, you are 63 // when the RootView is destroyed. If you remove a view from the tree, you are
63 // then responsible for cleaning up after it. 64 // then responsible for cleaning up after it.
64 // 65 //
65 /////////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////////
66 class WidgetWin : public Widget, 67 class WidgetWin : public base::WindowImpl,
68 public Widget,
67 public MessageLoopForUI::Observer, 69 public MessageLoopForUI::Observer,
68 public FocusTraversable, 70 public FocusTraversable,
69 public AcceleratorTarget { 71 public AcceleratorTarget {
70 public: 72 public:
71 WidgetWin(); 73 WidgetWin();
72 virtual ~WidgetWin(); 74 virtual ~WidgetWin();
73 75
74 // Sets the window styles. This is ONLY used when the window is created. 76 // Returns the RootView associated with the specified HWND (if any).
75 // In other words, if you invoke this after invoking Init, nothing happens. 77 static RootView* FindRootView(HWND hwnd);
76 void set_window_style(DWORD style) { window_style_ = style; }
77 DWORD window_style() const { return window_style_; }
78 78
79 // Sets the extended window styles. See comment about |set_window_style|. 79 // Returns the Widget associated with the specified HWND (if any).
80 void set_window_ex_style(DWORD style) { window_ex_style_ = style; } 80 static WidgetWin* GetWidget(HWND hwnd);
81 DWORD window_ex_style() const { return window_ex_style_; };
82
83 // Sets the class style to use. The default is CS_DBLCLKS.
84 void set_initial_class_style(UINT class_style) {
85 // We dynamically generate the class name, so don't register it globally!
86 DCHECK((class_style & CS_GLOBALCLASS) == 0);
87 class_style_ = class_style;
88 }
89 UINT initial_class_style() { return class_style_; }
90 81
91 void set_delete_on_destroy(bool delete_on_destroy) { 82 void set_delete_on_destroy(bool delete_on_destroy) {
92 delete_on_destroy_ = delete_on_destroy; 83 delete_on_destroy_ = delete_on_destroy;
93 } 84 }
94 85
95 // See description of use_layered_buffer_ for details. 86 // See description of use_layered_buffer_ for details.
96 void SetUseLayeredBuffer(bool use_layered_buffer); 87 void SetUseLayeredBuffer(bool use_layered_buffer);
97 88
98 // Disable Layered Window updates by setting to false. 89 // Disable Layered Window updates by setting to false.
99 void set_can_update_layered_window(bool can_update_layered_window) { 90 void set_can_update_layered_window(bool can_update_layered_window) {
100 can_update_layered_window_ = can_update_layered_window; 91 can_update_layered_window_ = can_update_layered_window;
101 } 92 }
102 93
103 // Returns the RootView associated with the specified HWND (if any). 94 BEGIN_MSG_MAP_EX(WidgetWin)
104 static RootView* FindRootView(HWND hwnd);
105
106 // Returns the Widget associated with the specified HWND (if any).
107 static WidgetWin* GetWidget(HWND hwnd);
108
109 // All classes registered by WidgetWin start with this name.
110 static const wchar_t* const kBaseClassName;
111
112 BEGIN_MSG_MAP_EX(0)
113 // Range handlers must go first! 95 // Range handlers must go first!
114 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) 96 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
115 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange) 97 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange)
116 98
117 // Reflected message handler 99 // Reflected message handler
118 MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage) 100 MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage)
119 101
120 // CustomFrameWindow hacks 102 // CustomFrameWindow hacks
121 MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) 103 MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption)
122 MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) 104 MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 291
310 // Resets the last move flag so that we can go around the optimization 292 // Resets the last move flag so that we can go around the optimization
311 // that disregards duplicate mouse moves when ending animation requires 293 // that disregards duplicate mouse moves when ending animation requires
312 // a new hit-test to do some highlighting as in TabStrip::RemoveTabAnimation 294 // a new hit-test to do some highlighting as in TabStrip::RemoveTabAnimation
313 // to cause the close button to highlight. 295 // to cause the close button to highlight.
314 void ResetLastMouseMoveFlag() { 296 void ResetLastMouseMoveFlag() {
315 last_mouse_event_was_move_ = false; 297 last_mouse_event_was_move_ = false;
316 } 298 }
317 299
318 protected: 300 protected:
319 // Call close instead of this to Destroy the window. 301 // Overridden from WindowImpl:
320 BOOL DestroyWindow() { 302 virtual HICON GetDefaultWindowIcon() const;
321 DCHECK(::IsWindow(GetNativeView())); 303 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param);
322 return ::DestroyWindow(GetNativeView());
323 }
324 304
325 // Message Handlers 305 // Message Handlers
326 // These are all virtual so that specialized Widgets can modify or augment 306 // These are all virtual so that specialized Widgets can modify or augment
327 // processing. 307 // processing.
328 // This list is in _ALPHABETICAL_ order! 308 // This list is in _ALPHABETICAL_ order!
329 // Note: in the base class these functions must do nothing but convert point 309 // Note: in the base class these functions must do nothing but convert point
330 // coordinates to client coordinates (if necessary) and forward the 310 // coordinates to client coordinates (if necessary) and forward the
331 // handling to the appropriate Process* function. This is so that 311 // handling to the appropriate Process* function. This is so that
332 // subclasses can easily override these methods to do different things 312 // subclasses can easily override these methods to do different things
333 // and have a convenient function to call to get the default behavior. 313 // and have a convenient function to call to get the default behavior.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 void PaintLayeredWindow(); 518 void PaintLayeredWindow();
539 519
540 // In layered mode, update the layered window. |dib_dc| represents a handle 520 // In layered mode, update the layered window. |dib_dc| represents a handle
541 // to a device context that contains the contents of the window. 521 // to a device context that contains the contents of the window.
542 void UpdateWindowFromContents(HDC dib_dc); 522 void UpdateWindowFromContents(HDC dib_dc);
543 523
544 // Invoked from WM_DESTROY. Does appropriate cleanup and invokes OnDestroy 524 // Invoked from WM_DESTROY. Does appropriate cleanup and invokes OnDestroy
545 // so that subclasses can do any cleanup they need to. 525 // so that subclasses can do any cleanup they need to.
546 void OnDestroyImpl(); 526 void OnDestroyImpl();
547 527
548 // The windows procedure used by all WidgetWins.
549 static LRESULT CALLBACK WndProc(HWND window,
550 UINT message,
551 WPARAM w_param,
552 LPARAM l_param);
553
554 // Called after the WM_ACTIVATE message has been processed by the default 528 // Called after the WM_ACTIVATE message has been processed by the default
555 // windows procedure. 529 // windows procedure.
556 static void PostProcessActivateMessage(WidgetWin* widget, 530 static void PostProcessActivateMessage(WidgetWin* widget,
557 int activation_state); 531 int activation_state);
558 532
559 // Gets the window class name to use when creating the corresponding HWND.
560 // If necessary, this registers the window class.
561 std::wstring GetWindowClassName();
562
563 // The following factory is used for calls to close the WidgetWin 533 // The following factory is used for calls to close the WidgetWin
564 // instance. 534 // instance.
565 ScopedRunnableMethodFactory<WidgetWin> close_widget_factory_; 535 ScopedRunnableMethodFactory<WidgetWin> close_widget_factory_;
566 536
567 // The flags currently being used with TrackMouseEvent to track mouse 537 // The flags currently being used with TrackMouseEvent to track mouse
568 // messages. 0 if there is no active tracking. The value of this member is 538 // messages. 0 if there is no active tracking. The value of this member is
569 // used when tracking is canceled. 539 // used when tracking is canceled.
570 DWORD active_mouse_tracking_flags_; 540 DWORD active_mouse_tracking_flags_;
571 541
572 bool opaque_; 542 bool opaque_;
573 543
574 // Window Styles used when creating the window.
575 DWORD window_style_;
576
577 // Window Extended Styles used when creating the window.
578 DWORD window_ex_style_;
579
580 // Style of the class to use.
581 UINT class_style_;
582
583 // Should we keep an offscreen buffer? This is initially true and if the 544 // Should we keep an offscreen buffer? This is initially true and if the
584 // window has WS_EX_LAYERED then it remains true. You can set this to false 545 // window has WS_EX_LAYERED then it remains true. You can set this to false
585 // at any time to ditch the buffer, and similarly set back to true to force 546 // at any time to ditch the buffer, and similarly set back to true to force
586 // creation of the buffer. 547 // creation of the buffer.
587 // 548 //
588 // NOTE: this is intended to be used with a layered window (a window with an 549 // NOTE: this is intended to be used with a layered window (a window with an
589 // extended window style of WS_EX_LAYERED). If you are using a layered window 550 // extended window style of WS_EX_LAYERED). If you are using a layered window
590 // and NOT changing the layered alpha or anything else, then leave this value 551 // and NOT changing the layered alpha or anything else, then leave this value
591 // alone. OTOH if you are invoking SetLayeredWindowAttributes then you'll 552 // alone. OTOH if you are invoking SetLayeredWindowAttributes then you'll
592 // must likely want to set this to false, or after changing the alpha toggle 553 // must likely want to set this to false, or after changing the alpha toggle
(...skipping 24 matching lines...) Expand all
617 bool last_mouse_event_was_move_; 578 bool last_mouse_event_was_move_;
618 579
619 // Coordinates of the last mouse move event, in screen coordinates. 580 // Coordinates of the last mouse move event, in screen coordinates.
620 int last_mouse_move_x_; 581 int last_mouse_move_x_;
621 int last_mouse_move_y_; 582 int last_mouse_move_y_;
622 583
623 // Instance of accessibility information and handling for MSAA root 584 // Instance of accessibility information and handling for MSAA root
624 CComPtr<IAccessible> accessibility_root_; 585 CComPtr<IAccessible> accessibility_root_;
625 586
626 scoped_ptr<DefaultThemeProvider> default_theme_provider_; 587 scoped_ptr<DefaultThemeProvider> default_theme_provider_;
627
628 // Our hwnd.
629 HWND hwnd_;
630 }; 588 };
631 589
632 } // namespace views 590 } // namespace views
633 591
634 #endif // #ifndef VIEWS_WIDGET_WIDGET_WIN_H_ 592 #endif // VIEWS_WIDGET_WIDGET_WIN_H_
OLDNEW
« no previous file with comments | « base/window_impl.cc ('k') | views/widget/widget_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698