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

Side by Side Diff: views/widget/native_widget_win.cc

Issue 7054052: Move more from Window onto Widget. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | « views/widget/native_widget_win.h ('k') | views/widget/widget.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "views/widget/native_widget_win.h" 5 #include "views/widget/native_widget_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/system_monitor/system_monitor.h" 10 #include "base/system_monitor/system_monitor.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 // Tells the window its frame (non-client area) has changed. 178 // Tells the window its frame (non-client area) has changed.
179 void SendFrameChanged(HWND window) { 179 void SendFrameChanged(HWND window) {
180 SetWindowPos(window, NULL, 0, 0, 0, 0, 180 SetWindowPos(window, NULL, 0, 0, 0, 0,
181 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS | 181 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
182 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION | 182 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
183 SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER); 183 SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
184 } 184 }
185 185
186 // Enables or disables the menu item for the specified command and menu.
187 void EnableMenuItem(HMENU menu, UINT command, bool enabled) {
188 UINT flags = MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
189 EnableMenuItem(menu, command, flags);
190 }
191
192 BOOL CALLBACK EnumChildWindowsForRedraw(HWND hwnd, LPARAM lparam) {
193 DWORD process_id;
194 GetWindowThreadProcessId(hwnd, &process_id);
195 int flags = RDW_INVALIDATE | RDW_NOCHILDREN | RDW_FRAME;
196 if (process_id == GetCurrentProcessId())
197 flags |= RDW_UPDATENOW;
198 RedrawWindow(hwnd, NULL, NULL, flags);
199 return TRUE;
200 }
201
186 // Links the HWND to its NativeWidget. 202 // Links the HWND to its NativeWidget.
187 const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__"; 203 const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__";
188 204
189 // A custom MSAA object id used to determine if a screen reader is actively 205 // A custom MSAA object id used to determine if a screen reader is actively
190 // listening for MSAA events. 206 // listening for MSAA events.
191 const int kCustomObjectID = 1; 207 const int kCustomObjectID = 1;
192 208
193 // If the hung renderer warning doesn't fit on screen, the amount of padding to 209 // If the hung renderer warning doesn't fit on screen, the amount of padding to
194 // be left between the edge of the window and the edge of the nearest monitor, 210 // be left between the edge of the window and the edge of the nearest monitor,
195 // after the window is nudged back on screen. Pixels. 211 // after the window is nudged back on screen. Pixels.
196 const int kMonitorEdgePadding = 10; 212 const int kMonitorEdgePadding = 10;
197 213
198 const int kDragFrameWindowAlpha = 200; 214 const int kDragFrameWindowAlpha = 200;
199 215
200 } // namespace 216 } // namespace
201 217
202 // static 218 // static
203 bool NativeWidgetWin::screen_reader_active_ = false; 219 bool NativeWidgetWin::screen_reader_active_ = false;
204 220
221 // A scoping class that prevents a window from being able to redraw in response
222 // to invalidations that may occur within it for the lifetime of the object.
223 //
224 // Why would we want such a thing? Well, it turns out Windows has some
225 // "unorthodox" behavior when it comes to painting its non-client areas.
226 // Occasionally, Windows will paint portions of the default non-client area
227 // right over the top of the custom frame. This is not simply fixed by handling
228 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this
229 // rendering is being done *inside* the default implementation of some message
230 // handlers and functions:
231 // . WM_SETTEXT
232 // . WM_SETICON
233 // . WM_NCLBUTTONDOWN
234 // . EnableMenuItem, called from our WM_INITMENU handler
235 // The solution is to handle these messages and call DefWindowProc ourselves,
236 // but prevent the window from being able to update itself for the duration of
237 // the call. We do this with this class, which automatically calls its
238 // associated Window's lock and unlock functions as it is created and destroyed.
239 // See documentation in those methods for the technique used.
240 //
241 // IMPORTANT: Do not use this scoping object for large scopes or periods of
242 // time! IT WILL PREVENT THE WINDOW FROM BEING REDRAWN! (duh).
243 //
244 // I would love to hear Raymond Chen's explanation for all this. And maybe a
245 // list of other messages that this applies to ;-)
246 class NativeWidgetWin::ScopedRedrawLock {
247 public:
248 explicit ScopedRedrawLock(NativeWidgetWin* widget) : widget_(widget) {
249 widget_->LockUpdates();
250 }
251
252 ~ScopedRedrawLock() {
253 widget_->UnlockUpdates();
254 }
255
256 private:
257 // The widget having its style changed.
258 NativeWidgetWin* widget_;
259 };
260
205 //////////////////////////////////////////////////////////////////////////////// 261 ////////////////////////////////////////////////////////////////////////////////
206 // NativeWidgetWin, public: 262 // NativeWidgetWin, public:
207 263
208 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate) 264 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate)
209 : is_window_(false), 265 : is_window_(false),
210 delegate_(delegate), 266 delegate_(delegate),
211 close_widget_factory_(this), 267 close_widget_factory_(this),
212 active_mouse_tracking_flags_(0), 268 active_mouse_tracking_flags_(0),
213 use_layered_buffer_(false), 269 use_layered_buffer_(false),
214 layered_alpha_(255), 270 layered_alpha_(255),
215 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), 271 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)),
216 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 272 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
217 can_update_layered_window_(true), 273 can_update_layered_window_(true),
218 focus_on_creation_(true), 274 focus_on_creation_(true),
219 restore_focus_when_enabled_(false), 275 restore_focus_when_enabled_(false),
220 accessibility_view_events_index_(-1), 276 accessibility_view_events_index_(-1),
221 accessibility_view_events_(kMaxAccessibilityViewEvents), 277 accessibility_view_events_(kMaxAccessibilityViewEvents),
222 previous_cursor_(NULL), 278 previous_cursor_(NULL),
223 is_input_method_win_(false), 279 is_input_method_win_(false),
224 fullscreen_(false), 280 fullscreen_(false),
225 force_hidden_count_(0) { 281 force_hidden_count_(0),
282 lock_updates_(false),
283 saved_window_style_(0) {
226 } 284 }
227 285
228 NativeWidgetWin::~NativeWidgetWin() { 286 NativeWidgetWin::~NativeWidgetWin() {
229 // We need to delete the input method before calling DestroyRootView(), 287 // We need to delete the input method before calling DestroyRootView(),
230 // because it'll set focus_manager_ to NULL. 288 // because it'll set focus_manager_ to NULL.
231 input_method_.reset(); 289 input_method_.reset();
232 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 290 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
233 delete delegate_; 291 delete delegate_;
234 } 292 }
235 293
236 // static 294 // static
237 bool NativeWidgetWin::IsAeroGlassEnabled() { 295 bool NativeWidgetWin::IsAeroGlassEnabled() {
238 if (base::win::GetVersion() < base::win::VERSION_VISTA) 296 if (base::win::GetVersion() < base::win::VERSION_VISTA)
239 return false; 297 return false;
240 // If composition is not enabled, we behave like on XP. 298 // If composition is not enabled, we behave like on XP.
241 BOOL enabled = FALSE; 299 BOOL enabled = FALSE;
242 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled; 300 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled;
243 } 301 }
244 302
303 void NativeWidgetWin::Show(int show_state) {
304 ShowWindow(show_state);
305 // When launched from certain programs like bash and Windows Live Messenger,
306 // show_state is set to SW_HIDE, so we need to correct that condition. We
307 // don't just change show_state to SW_SHOWNORMAL because MSDN says we must
308 // always first call ShowWindow with the specified value from STARTUPINFO,
309 // otherwise all future ShowWindow calls will be ignored (!!#@@#!). Instead,
310 // we call ShowWindow again in this case.
311 if (show_state == SW_HIDE) {
312 show_state = SW_SHOWNORMAL;
313 ShowWindow(show_state);
314 }
315
316 // We need to explicitly activate the window if we've been shown with a state
317 // that should activate, because if we're opened from a desktop shortcut while
318 // an existing window is already running it doesn't seem to be enough to use
319 // one of these flags to activate the window.
320 if (show_state == SW_SHOWNORMAL || show_state == SW_SHOWMAXIMIZED)
321 Activate();
322
323 SetInitialFocus();
324 }
325
245 View* NativeWidgetWin::GetAccessibilityViewEventAt(int id) { 326 View* NativeWidgetWin::GetAccessibilityViewEventAt(int id) {
246 // Convert from MSAA child id. 327 // Convert from MSAA child id.
247 id = -(id + 1); 328 id = -(id + 1);
248 DCHECK(id >= 0 && id < kMaxAccessibilityViewEvents); 329 DCHECK(id >= 0 && id < kMaxAccessibilityViewEvents);
249 return accessibility_view_events_[id]; 330 return accessibility_view_events_[id];
250 } 331 }
251 332
252 int NativeWidgetWin::AddAccessibilityViewEvent(View* view) { 333 int NativeWidgetWin::AddAccessibilityViewEvent(View* view) {
253 accessibility_view_events_index_ = 334 accessibility_view_events_index_ =
254 (accessibility_view_events_index_ + 1) % kMaxAccessibilityViewEvents; 335 (accessibility_view_events_index_ + 1) % kMaxAccessibilityViewEvents;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 624 }
544 625
545 gfx::Rect NativeWidgetWin::GetClientAreaScreenBounds() const { 626 gfx::Rect NativeWidgetWin::GetClientAreaScreenBounds() const {
546 RECT r; 627 RECT r;
547 GetClientRect(&r); 628 GetClientRect(&r);
548 POINT point = { r.left, r.top }; 629 POINT point = { r.left, r.top };
549 ClientToScreen(hwnd(), &point); 630 ClientToScreen(hwnd(), &point);
550 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); 631 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top);
551 } 632 }
552 633
634 gfx::Rect NativeWidgetWin::GetRestoredBounds() const {
635 // If we're in fullscreen mode, we've changed the normal bounds to the monitor
636 // rect, so return the saved bounds instead.
637 if (IsFullscreen())
638 return gfx::Rect(saved_window_info_.window_rect);
639
640 gfx::Rect bounds;
641 GetWindowBoundsAndMaximizedState(&bounds, NULL);
642 return bounds;
643 }
644
553 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { 645 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) {
554 LONG style = GetWindowLong(GWL_STYLE); 646 LONG style = GetWindowLong(GWL_STYLE);
555 if (style & WS_MAXIMIZE) 647 if (style & WS_MAXIMIZE)
556 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE); 648 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE);
557 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), 649 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
558 SWP_NOACTIVATE | SWP_NOZORDER); 650 SWP_NOACTIVATE | SWP_NOZORDER);
559 } 651 }
560 652
561 void NativeWidgetWin::SetSize(const gfx::Size& size) { 653 void NativeWidgetWin::SetSize(const gfx::Size& size) {
562 SetWindowPos(NULL, 0, 0, size.width(), size.height(), 654 SetWindowPos(NULL, 0, 0, size.width(), size.height(),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 is_input_method_win_ = false; 712 is_input_method_win_ = false;
621 713
622 // We may already have been destroyed if the selection resulted in a tab 714 // We may already have been destroyed if the selection resulted in a tab
623 // switch which will have reactivated the browser window and closed us, so 715 // switch which will have reactivated the browser window and closed us, so
624 // we need to check to see if we're still a window before trying to destroy 716 // we need to check to see if we're still a window before trying to destroy
625 // ourself. 717 // ourself.
626 if (IsWindow()) 718 if (IsWindow())
627 DestroyWindow(hwnd()); 719 DestroyWindow(hwnd());
628 } 720 }
629 721
722 void NativeWidgetWin::EnableClose(bool enable) {
723 // Disable the native frame's close button regardless of whether or not the
724 // native frame is in use, since this also affects the system menu.
725 EnableMenuItem(GetSystemMenu(GetNativeView(), false), SC_CLOSE, enable);
726 SendFrameChanged(GetNativeView());
727 }
728
630 void NativeWidgetWin::Show() { 729 void NativeWidgetWin::Show() {
631 if (!IsWindow()) 730 if (!IsWindow())
632 return; 731 return;
633 732
634 ShowWindow(SW_SHOWNOACTIVATE); 733 ShowWindow(SW_SHOWNOACTIVATE);
635 SetInitialFocus(); 734 SetInitialFocus();
636 } 735 }
637 736
638 void NativeWidgetWin::Hide() { 737 void NativeWidgetWin::Hide() {
639 if (IsWindow()) { 738 if (IsWindow()) {
640 // NOTE: Be careful not to activate any windows here (for example, calling 739 // NOTE: Be careful not to activate any windows here (for example, calling
641 // ShowWindow(SW_HIDE) will automatically activate another window). This 740 // ShowWindow(SW_HIDE) will automatically activate another window). This
642 // code can be called while a window is being deactivated, and activating 741 // code can be called while a window is being deactivated, and activating
643 // another window will screw up the activation that is already in progress. 742 // another window will screw up the activation that is already in progress.
644 SetWindowPos(NULL, 0, 0, 0, 0, 743 SetWindowPos(NULL, 0, 0, 0, 0,
645 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | 744 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
646 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); 745 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
647 } 746 }
648 } 747 }
649 748
749 void NativeWidgetWin::ShowNativeWidget(ShowState state) {
750 DWORD native_show_state;
751 switch (state) {
752 case SHOW_INACTIVE:
753 native_show_state = SW_SHOWNOACTIVATE;
754 break;
755 case SHOW_MAXIMIZED:
756 native_show_state = SW_SHOWMAXIMIZED;
757 break;
758 default:
759 native_show_state = GetShowState();
760 break;
761 }
762 Show(native_show_state);
763 }
764
650 bool NativeWidgetWin::IsVisible() const { 765 bool NativeWidgetWin::IsVisible() const {
651 return !!::IsWindowVisible(hwnd()); 766 return !!::IsWindowVisible(hwnd());
652 } 767 }
653 768
654 void NativeWidgetWin::Activate() { 769 void NativeWidgetWin::Activate() {
655 if (IsMinimized()) 770 if (IsMinimized())
656 ::ShowWindow(GetNativeView(), SW_RESTORE); 771 ::ShowWindow(GetNativeView(), SW_RESTORE);
657 ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0, 772 ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0,
658 SWP_NOSIZE | SWP_NOMOVE); 773 SWP_NOSIZE | SWP_NOMOVE);
659 SetForegroundWindow(GetNativeView()); 774 SetForegroundWindow(GetNativeView());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 //////////////////////////////////////////////////////////////////////////////// 989 ////////////////////////////////////////////////////////////////////////////////
875 // NativeWidgetWin, protected: 990 // NativeWidgetWin, protected:
876 991
877 // Message handlers ------------------------------------------------------------ 992 // Message handlers ------------------------------------------------------------
878 993
879 void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) { 994 void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) {
880 SetMsgHandled(FALSE); 995 SetMsgHandled(FALSE);
881 } 996 }
882 997
883 void NativeWidgetWin::OnActivateApp(BOOL active, DWORD thread_id) { 998 void NativeWidgetWin::OnActivateApp(BOOL active, DWORD thread_id) {
884 SetMsgHandled(FALSE); 999 if (GetWidget()->non_client_view() && !active &&
1000 thread_id != GetCurrentThreadId()) {
1001 // Another application was activated, we should reset any state that
1002 // disables inactive rendering now.
1003 delegate_->EnableInactiveRendering();
1004 // Update the native frame too, since it could be rendering the non-client
1005 // area.
1006 CallDefaultNCActivateHandler(FALSE);
1007 }
885 } 1008 }
886 1009
887 LRESULT NativeWidgetWin::OnAppCommand(HWND window, 1010 LRESULT NativeWidgetWin::OnAppCommand(HWND window,
888 short app_command, 1011 short app_command,
889 WORD device, 1012 WORD device,
890 int keystate) { 1013 int keystate) {
891 // We treat APPCOMMAND ids as an extension of our command namespace, and just 1014 // We treat APPCOMMAND ids as an extension of our command namespace, and just
892 // let the delegate figure out what to do... 1015 // let the delegate figure out what to do...
893 return GetWidget()->widget_delegate()->ExecuteWindowsCommand(app_command); 1016 return GetWidget()->widget_delegate()->ExecuteWindowsCommand(app_command);
894 } 1017 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 if (delegate_->HasFocusManager() && 1090 if (delegate_->HasFocusManager() &&
968 NativeTextfieldViews::IsTextfieldViewsEnabled()) { 1091 NativeTextfieldViews::IsTextfieldViewsEnabled()) {
969 input_method_.reset(new InputMethodWin(this)); 1092 input_method_.reset(new InputMethodWin(this));
970 input_method_->Init(GetWidget()); 1093 input_method_->Init(GetWidget());
971 is_input_method_win_ = true; 1094 is_input_method_win_ = true;
972 } 1095 }
973 return 0; 1096 return 0;
974 } 1097 }
975 1098
976 void NativeWidgetWin::OnDestroy() { 1099 void NativeWidgetWin::OnDestroy() {
1100 delegate_->OnNativeWidgetDestroying();
977 if (drop_target_.get()) { 1101 if (drop_target_.get()) {
978 RevokeDragDrop(hwnd()); 1102 RevokeDragDrop(hwnd());
979 drop_target_ = NULL; 1103 drop_target_ = NULL;
980 } 1104 }
981 1105
982 props_.reset(); 1106 props_.reset();
983 } 1107 }
984 1108
985 void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { 1109 void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) {
986 GetWidget()->widget_delegate()->OnDisplayChanged(); 1110 GetWidget()->widget_delegate()->OnDisplayChanged();
987 } 1111 }
988 1112
989 LRESULT NativeWidgetWin::OnDwmCompositionChanged(UINT msg, 1113 LRESULT NativeWidgetWin::OnDwmCompositionChanged(UINT msg,
990 WPARAM w_param, 1114 WPARAM w_param,
991 LPARAM l_param) { 1115 LPARAM l_param) {
992 SetMsgHandled(FALSE); 1116 if (!GetWidget()->non_client_view()) {
1117 SetMsgHandled(FALSE);
1118 return 0;
1119 }
1120
1121 // For some reason, we need to hide the window while we're changing the frame
1122 // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED.
1123 // If we don't, the client area will be filled with black. I'm suspecting
1124 // something skia-ey.
1125 // Frame type toggling caused by the user (e.g. switching theme) doesn't seem
1126 // to have this requirement.
1127 FrameTypeChanged();
993 return 0; 1128 return 0;
994 } 1129 }
995 1130
996 void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) { 1131 void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) {
997 SetMsgHandled(FALSE); 1132 SetMsgHandled(FALSE);
998 } 1133 }
999 1134
1000 void NativeWidgetWin::OnEnterSizeMove() { 1135 void NativeWidgetWin::OnEnterSizeMove() {
1136 delegate_->OnNativeWidgetBeginUserBoundsChange();
1001 SetMsgHandled(FALSE); 1137 SetMsgHandled(FALSE);
1002 } 1138 }
1003 1139
1004 LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) { 1140 LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) {
1005 // This is needed for magical win32 flicker ju-ju. 1141 // This is needed for magical win32 flicker ju-ju.
1006 return 1; 1142 return 1;
1007 } 1143 }
1008 1144
1009 void NativeWidgetWin::OnExitMenuLoop(BOOL is_track_popup_menu) { 1145 void NativeWidgetWin::OnExitMenuLoop(BOOL is_track_popup_menu) {
1010 SetMsgHandled(FALSE); 1146 SetMsgHandled(FALSE);
1011 } 1147 }
1012 1148
1013 void NativeWidgetWin::OnExitSizeMove() { 1149 void NativeWidgetWin::OnExitSizeMove() {
1150 delegate_->OnNativeWidgetEndUserBoundsChange();
1014 SetMsgHandled(FALSE); 1151 SetMsgHandled(FALSE);
1015 } 1152 }
1016 1153
1017 LRESULT NativeWidgetWin::OnGetObject(UINT uMsg, 1154 LRESULT NativeWidgetWin::OnGetObject(UINT uMsg,
1018 WPARAM w_param, 1155 WPARAM w_param,
1019 LPARAM l_param) { 1156 LPARAM l_param) {
1020 LRESULT reference_result = static_cast<LRESULT>(0L); 1157 LRESULT reference_result = static_cast<LRESULT>(0L);
1021 1158
1022 // Accessibility readers will send an OBJID_CLIENT message 1159 // Accessibility readers will send an OBJID_CLIENT message
1023 if (OBJID_CLIENT == l_param) { 1160 if (OBJID_CLIENT == l_param) {
(...skipping 13 matching lines...) Expand all
1037 OnScreenReaderDetected(); 1174 OnScreenReaderDetected();
1038 1175
1039 // Return with failure. 1176 // Return with failure.
1040 return static_cast<LRESULT>(0L); 1177 return static_cast<LRESULT>(0L);
1041 } 1178 }
1042 1179
1043 return reference_result; 1180 return reference_result;
1044 } 1181 }
1045 1182
1046 void NativeWidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 1183 void NativeWidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
1184 gfx::Size min_window_size(delegate_->GetMinimumSize());
1185 minmax_info->ptMinTrackSize.x = min_window_size.width();
1186 minmax_info->ptMinTrackSize.y = min_window_size.height();
1047 SetMsgHandled(FALSE); 1187 SetMsgHandled(FALSE);
1048 } 1188 }
1049 1189
1050 void NativeWidgetWin::OnHScroll(int scroll_type, 1190 void NativeWidgetWin::OnHScroll(int scroll_type,
1051 short position, 1191 short position,
1052 HWND scrollbar) { 1192 HWND scrollbar) {
1053 SetMsgHandled(FALSE); 1193 SetMsgHandled(FALSE);
1054 } 1194 }
1055 1195
1056 LRESULT NativeWidgetWin::OnImeMessages(UINT message, 1196 LRESULT NativeWidgetWin::OnImeMessages(UINT message,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 default: 1228 default:
1089 NOTREACHED() << "Unknown IME message:" << message; 1229 NOTREACHED() << "Unknown IME message:" << message;
1090 break; 1230 break;
1091 } 1231 }
1092 1232
1093 SetMsgHandled(handled); 1233 SetMsgHandled(handled);
1094 return result; 1234 return result;
1095 } 1235 }
1096 1236
1097 void NativeWidgetWin::OnInitMenu(HMENU menu) { 1237 void NativeWidgetWin::OnInitMenu(HMENU menu) {
1098 SetMsgHandled(FALSE); 1238 // We only need to manually enable the system menu if we're not using a native
1239 // frame.
1240 if (GetWidget()->ShouldUseNativeFrame()) {
1241 SetMsgHandled(FALSE);
1242 return;
1243 }
1244
1245 bool is_fullscreen = IsFullscreen();
1246 bool is_minimized = IsMinimized();
1247 bool is_maximized = IsMaximized();
1248 bool is_restored = !is_fullscreen && !is_minimized && !is_maximized;
1249
1250 ScopedRedrawLock lock(this);
1251 EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized);
1252 EnableMenuItem(menu, SC_MOVE, is_restored);
1253 EnableMenuItem(menu, SC_SIZE,
1254 GetWidget()->widget_delegate()->CanResize() && is_restored);
1255 EnableMenuItem(menu, SC_MAXIMIZE,
1256 GetWidget()->widget_delegate()->CanMaximize() &&
1257 !is_fullscreen && !is_maximized);
1258 EnableMenuItem(menu, SC_MINIMIZE,
1259 GetWidget()->widget_delegate()->CanMaximize() &&
1260 !is_minimized);
1099 } 1261 }
1100 1262
1101 void NativeWidgetWin::OnInitMenuPopup(HMENU menu, 1263 void NativeWidgetWin::OnInitMenuPopup(HMENU menu,
1102 UINT position, 1264 UINT position,
1103 BOOL is_system_menu) { 1265 BOOL is_system_menu) {
1104 SetMsgHandled(FALSE); 1266 SetMsgHandled(FALSE);
1105 } 1267 }
1106 1268
1107 void NativeWidgetWin::OnInputLangChange(DWORD character_set, 1269 void NativeWidgetWin::OnInputLangChange(DWORD character_set,
1108 HKL input_language_id) { 1270 HKL input_language_id) {
(...skipping 18 matching lines...) Expand all
1127 void NativeWidgetWin::OnKillFocus(HWND focused_window) { 1289 void NativeWidgetWin::OnKillFocus(HWND focused_window) {
1128 delegate_->OnNativeBlur(focused_window); 1290 delegate_->OnNativeBlur(focused_window);
1129 if (input_method_.get()) 1291 if (input_method_.get())
1130 input_method_->OnBlur(); 1292 input_method_->OnBlur();
1131 SetMsgHandled(FALSE); 1293 SetMsgHandled(FALSE);
1132 } 1294 }
1133 1295
1134 LRESULT NativeWidgetWin::OnMouseActivate(UINT message, 1296 LRESULT NativeWidgetWin::OnMouseActivate(UINT message,
1135 WPARAM w_param, 1297 WPARAM w_param,
1136 LPARAM l_param) { 1298 LPARAM l_param) {
1299 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent
1300 // line.
1301 if (GetWidget()->non_client_view())
1302 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT;
1137 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) 1303 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)
1138 return MA_NOACTIVATE; 1304 return MA_NOACTIVATE;
1139 SetMsgHandled(FALSE); 1305 SetMsgHandled(FALSE);
1140 return MA_ACTIVATE; 1306 return MA_ACTIVATE;
1141 } 1307 }
1142 1308
1143 LRESULT NativeWidgetWin::OnMouseRange(UINT message, 1309 LRESULT NativeWidgetWin::OnMouseRange(UINT message,
1144 WPARAM w_param, 1310 WPARAM w_param,
1145 LPARAM l_param) { 1311 LPARAM l_param) {
1146 MSG msg = { hwnd(), message, w_param, l_param, 0, 1312 MSG msg = { hwnd(), message, w_param, l_param, 0,
(...skipping 29 matching lines...) Expand all
1176 GetWidget()->widget_delegate()->OnWidgetMove(); 1342 GetWidget()->widget_delegate()->OnWidgetMove();
1177 SetMsgHandled(FALSE); 1343 SetMsgHandled(FALSE);
1178 } 1344 }
1179 1345
1180 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { 1346 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) {
1181 // TODO(beng): move to Widget. 1347 // TODO(beng): move to Widget.
1182 GetWidget()->widget_delegate()->OnWidgetMove(); 1348 GetWidget()->widget_delegate()->OnWidgetMove();
1183 } 1349 }
1184 1350
1185 LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { 1351 LRESULT NativeWidgetWin::OnNCActivate(BOOL active) {
1186 SetMsgHandled(FALSE); 1352 if (!GetWidget()->non_client_view()) {
1187 return 0; 1353 SetMsgHandled(FALSE);
1354 return 0;
1355 }
1356
1357 if (!delegate_->CanActivate())
1358 return TRUE;
1359
1360 delegate_->OnNativeWidgetActivationChanged(!!active);
1361
1362 // The frame may need to redraw as a result of the activation change.
1363 // We can get WM_NCACTIVATE before we're actually visible. If we're not
1364 // visible, no need to paint.
1365 if (IsVisible())
1366 GetWidget()->non_client_view()->SchedulePaint();
1367
1368 if (!GetWidget()->ShouldUseNativeFrame()) {
1369 // TODO(beng, et al): Hack to redraw this window and child windows
1370 // synchronously upon activation. Not all child windows are redrawing
1371 // themselves leading to issues like http://crbug.com/74604
1372 // We redraw out-of-process HWNDs asynchronously to avoid hanging the
1373 // whole app if a child HWND belonging to a hung plugin is encountered.
1374 RedrawWindow(GetNativeView(), NULL, NULL,
1375 RDW_NOCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW);
1376 EnumChildWindows(GetNativeView(), EnumChildWindowsForRedraw, NULL);
1377 }
1378
1379 // If we're active again, we should be allowed to render as inactive, so
1380 // tell the non-client view.
1381 bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled();
1382 if (IsActive())
1383 delegate_->EnableInactiveRendering();
1384
1385 return CallDefaultNCActivateHandler(inactive_rendering_disabled || active);
1188 } 1386 }
1189 1387
1190 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) { 1388 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) {
1191 SetMsgHandled(FALSE); 1389 SetMsgHandled(FALSE);
1192 return 0; 1390 return 0;
1193 } 1391 }
1194 1392
1195 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& pt) { 1393 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) {
1394 if (!GetWidget()->non_client_view()) {
1395 SetMsgHandled(FALSE);
1396 return 0;
1397 }
1398
1399 // If the DWM is rendering the window controls, we need to give the DWM's
1400 // default window procedure first chance to handle hit testing.
1401 if (GetWidget()->ShouldUseNativeFrame()) {
1402 LRESULT result;
1403 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
1404 MAKELPARAM(point.x, point.y), &result)) {
1405 return result;
1406 }
1407 }
1408
1409 // First, give the NonClientView a chance to test the point to see if it
1410 // provides any of the non-client area.
1411 POINT temp = point;
1412 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1);
1413 int component = delegate_->GetNonClientComponent(gfx::Point(temp));
1414 if (component != HTNOWHERE)
1415 return component;
1416
1417 // Otherwise, we let Windows do all the native frame non-client handling for
1418 // us.
1196 SetMsgHandled(FALSE); 1419 SetMsgHandled(FALSE);
1197 return 0; 1420 return 0;
1198 } 1421 }
1199 1422
1200 void NativeWidgetWin::OnNCPaint(HRGN rgn) { 1423 void NativeWidgetWin::OnNCPaint(HRGN rgn) {
1201 SetMsgHandled(FALSE); 1424 SetMsgHandled(FALSE);
1202 } 1425 }
1203 1426
1204 LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT msg, 1427 LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT msg,
1205 WPARAM w_param, 1428 WPARAM w_param,
1206 LPARAM l_param) { 1429 LPARAM l_param) {
1207 SetMsgHandled(FALSE); 1430 // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for
1431 // an explanation about why we need to handle this message.
1432 SetMsgHandled(!GetWidget()->ShouldUseNativeFrame());
1208 return 0; 1433 return 0;
1209 } 1434 }
1210 1435
1211 LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT msg, 1436 LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT msg,
1212 WPARAM w_param, 1437 WPARAM w_param,
1213 LPARAM l_param) { 1438 LPARAM l_param) {
1214 SetMsgHandled(FALSE); 1439 // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for
1440 // an explanation about why we need to handle this message.
1441 SetMsgHandled(!GetWidget()->ShouldUseNativeFrame());
1215 return 0; 1442 return 0;
1216 } 1443 }
1217 1444
1218 LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) { 1445 LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) {
1219 // We can be sent this message before the tooltip manager is created, if a 1446 // We can be sent this message before the tooltip manager is created, if a
1220 // subclass overrides OnCreate and creates some kind of Windows control there 1447 // subclass overrides OnCreate and creates some kind of Windows control there
1221 // that sends WM_NOTIFY messages. 1448 // that sends WM_NOTIFY messages.
1222 if (tooltip_manager_.get()) { 1449 if (tooltip_manager_.get()) {
1223 bool handled; 1450 bool handled;
1224 LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); 1451 LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg, 1483 LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg,
1257 WPARAM w_param, 1484 WPARAM w_param,
1258 LPARAM l_param) { 1485 LPARAM l_param) {
1259 SetMsgHandled(FALSE); 1486 SetMsgHandled(FALSE);
1260 return 0; 1487 return 0;
1261 } 1488 }
1262 1489
1263 LRESULT NativeWidgetWin::OnSetCursor(UINT message, 1490 LRESULT NativeWidgetWin::OnSetCursor(UINT message,
1264 WPARAM w_param, 1491 WPARAM w_param,
1265 LPARAM l_param) { 1492 LPARAM l_param) {
1266 SetMsgHandled(FALSE); 1493 // This shouldn't hurt even if we're using the native frame.
1267 return 0; 1494 ScopedRedrawLock lock(this);
1495 return DefWindowProc(GetNativeView(), message, w_param, l_param);
1268 } 1496 }
1269 1497
1270 void NativeWidgetWin::OnSetFocus(HWND focused_window) { 1498 void NativeWidgetWin::OnSetFocus(HWND focused_window) {
1271 delegate_->OnNativeFocus(focused_window); 1499 delegate_->OnNativeFocus(focused_window);
1272 if (input_method_.get()) 1500 if (input_method_.get())
1273 input_method_->OnFocus(); 1501 input_method_->OnFocus();
1274 SetMsgHandled(FALSE); 1502 SetMsgHandled(FALSE);
1275 } 1503 }
1276 1504
1277 LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { 1505 LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) {
1278 SetMsgHandled(FALSE); 1506 // This shouldn't hurt even if we're using the native frame.
1279 return 0; 1507 ScopedRedrawLock lock(this);
1508 return DefWindowProc(GetNativeView(), WM_SETICON, size_type,
1509 reinterpret_cast<LPARAM>(new_icon));
1280 } 1510 }
1281 1511
1282 LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { 1512 LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) {
1283 SetMsgHandled(FALSE); 1513 // This shouldn't hurt even if we're using the native frame.
1284 return 0; 1514 ScopedRedrawLock lock(this);
1515 return DefWindowProc(GetNativeView(), WM_SETTEXT, NULL,
1516 reinterpret_cast<LPARAM>(text));
1285 } 1517 }
1286 1518
1287 void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { 1519 void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
1288 if (!GetParent() && (flags == SPI_SETWORKAREA) && 1520 if (!GetParent() && (flags == SPI_SETWORKAREA) &&
1289 !GetWidget()->widget_delegate()->WillProcessWorkAreaChange()) { 1521 !GetWidget()->widget_delegate()->WillProcessWorkAreaChange()) {
1290 // Fire a dummy SetWindowPos() call, so we'll trip the code in 1522 // Fire a dummy SetWindowPos() call, so we'll trip the code in
1291 // OnWindowPosChanging() below that notices work area changes. 1523 // OnWindowPosChanging() below that notices work area changes.
1292 ::SetWindowPos(GetNativeView(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | 1524 ::SetWindowPos(GetNativeView(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
1293 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); 1525 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
1294 SetMsgHandled(TRUE); 1526 SetMsgHandled(TRUE);
1295 } else { 1527 } else {
1296 // TODO(beng): move to Widget. 1528 // TODO(beng): move to Widget.
1297 if (flags == SPI_SETWORKAREA) 1529 if (flags == SPI_SETWORKAREA)
1298 GetWidget()->widget_delegate()->OnWorkAreaChanged(); 1530 GetWidget()->widget_delegate()->OnWorkAreaChanged();
1299 SetMsgHandled(FALSE); 1531 SetMsgHandled(FALSE);
1300 } 1532 }
1301 } 1533 }
1302 1534
1303 void NativeWidgetWin::OnSize(UINT param, const CSize& size) { 1535 void NativeWidgetWin::OnSize(UINT param, const CSize& size) {
1536 RedrawWindow(GetNativeView(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
1304 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've 1537 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
1305 // invoked OnSize we ensure the RootView has been laid out. 1538 // invoked OnSize we ensure the RootView has been laid out.
1306 ResetWindowRegion(false); 1539 ResetWindowRegion(false);
1307 } 1540 }
1308 1541
1309 void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { 1542 void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) {
1543 if (!GetWidget()->non_client_view())
1544 return;
1545
1546 // Windows uses the 4 lower order bits of |notification_code| for type-
1547 // specific information so we must exclude this when comparing.
1548 static const int sc_mask = 0xFFF0;
1549 // Ignore size/move/maximize in fullscreen mode.
1550 if (IsFullscreen() &&
1551 (((notification_code & sc_mask) == SC_SIZE) ||
1552 ((notification_code & sc_mask) == SC_MOVE) ||
1553 ((notification_code & sc_mask) == SC_MAXIMIZE)))
1554 return;
1555 if (!GetWidget()->ShouldUseNativeFrame()) {
1556 if ((notification_code & sc_mask) == SC_MINIMIZE ||
1557 (notification_code & sc_mask) == SC_MAXIMIZE ||
1558 (notification_code & sc_mask) == SC_RESTORE) {
1559 GetWidget()->non_client_view()->ResetWindowControls();
1560 } else if ((notification_code & sc_mask) == SC_MOVE ||
1561 (notification_code & sc_mask) == SC_SIZE) {
1562 if (lock_updates_) {
1563 // We were locked, before entering a resize or move modal loop. Now that
1564 // we've begun to move the window, we need to unlock updates so that the
1565 // sizing/moving feedback can be continuous.
1566 UnlockUpdates();
1567 }
1568 }
1569 }
1570
1571 // Handle SC_KEYMENU, which means that the user has pressed the ALT
1572 // key and released it, so we should focus the menu bar.
1573 if ((notification_code & sc_mask) == SC_KEYMENU && click.x == 0) {
1574 // Retrieve the status of shift and control keys to prevent consuming
1575 // shift+alt keys, which are used by Windows to change input languages.
1576 Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU),
1577 !!(GetKeyState(VK_SHIFT) & 0x8000),
1578 !!(GetKeyState(VK_CONTROL) & 0x8000),
1579 false);
1580 GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator);
1581 return;
1582 }
1583
1584 // If the delegate can't handle it, the system implementation will be called.
1585 if (!delegate_->ExecuteCommand(notification_code)) {
1586 DefWindowProc(GetNativeView(), WM_SYSCOMMAND, notification_code,
1587 MAKELPARAM(click.x, click.y));
1588 }
1310 } 1589 }
1311 1590
1312 void NativeWidgetWin::OnThemeChanged() { 1591 void NativeWidgetWin::OnThemeChanged() {
1313 // Notify NativeThemeWin. 1592 // Notify NativeThemeWin.
1314 gfx::NativeThemeWin::instance()->CloseHandles(); 1593 gfx::NativeThemeWin::instance()->CloseHandles();
1315 } 1594 }
1316 1595
1317 void NativeWidgetWin::OnVScroll(int scroll_type, 1596 void NativeWidgetWin::OnVScroll(int scroll_type,
1318 short position, 1597 short position,
1319 HWND scrollbar) { 1598 HWND scrollbar) {
(...skipping 18 matching lines...) Expand all
1338 1617
1339 void NativeWidgetWin::OnFinalMessage(HWND window) { 1618 void NativeWidgetWin::OnFinalMessage(HWND window) {
1340 delegate_->OnNativeWidgetDestroyed(); 1619 delegate_->OnNativeWidgetDestroyed();
1341 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 1620 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
1342 delete this; 1621 delete this;
1343 } 1622 }
1344 1623
1345 //////////////////////////////////////////////////////////////////////////////// 1624 ////////////////////////////////////////////////////////////////////////////////
1346 // NativeWidgetWin, protected: 1625 // NativeWidgetWin, protected:
1347 1626
1627 int NativeWidgetWin::GetShowState() const {
1628 return SW_SHOWNORMAL;
1629 }
1630
1631 gfx::Insets NativeWidgetWin::GetClientAreaInsets() const {
1632 // Returning an empty Insets object causes the default handling in
1633 // NativeWidgetWin::OnNCCalcSize() to be invoked.
1634 if (GetWidget()->ShouldUseNativeFrame())
1635 return gfx::Insets();
1636
1637 if (IsMaximized()) {
1638 // Windows automatically adds a standard width border to all sides when a
1639 // window is maximized.
1640 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
1641 return gfx::Insets(border_thickness, border_thickness, border_thickness,
1642 border_thickness);
1643 }
1644 // This is weird, but highly essential. If we don't offset the bottom edge
1645 // of the client rect, the window client area and window area will match,
1646 // and when returning to glass rendering mode from non-glass, the client
1647 // area will not paint black as transparent. This is because (and I don't
1648 // know why) the client area goes from matching the window rect to being
1649 // something else. If the client area is not the window rect in both
1650 // modes, the blackness doesn't occur. Because of this, we need to tell
1651 // the RootView to lay out to fit the window rect, rather than the client
1652 // rect when using the opaque frame.
1653 // Note: this is only required for non-fullscreen windows. Note that
1654 // fullscreen windows are in restored state, not maximized.
1655 return gfx::Insets(0, 0, IsFullscreen() ? 0 : 1, 0);
1656 }
1657
1348 void NativeWidgetWin::TrackMouseEvents(DWORD mouse_tracking_flags) { 1658 void NativeWidgetWin::TrackMouseEvents(DWORD mouse_tracking_flags) {
1349 // Begin tracking mouse events for this HWND so that we get WM_MOUSELEAVE 1659 // Begin tracking mouse events for this HWND so that we get WM_MOUSELEAVE
1350 // when the user moves the mouse outside this HWND's bounds. 1660 // when the user moves the mouse outside this HWND's bounds.
1351 if (active_mouse_tracking_flags_ == 0 || mouse_tracking_flags & TME_CANCEL) { 1661 if (active_mouse_tracking_flags_ == 0 || mouse_tracking_flags & TME_CANCEL) {
1352 if (mouse_tracking_flags & TME_CANCEL) { 1662 if (mouse_tracking_flags & TME_CANCEL) {
1353 // We're about to cancel active mouse tracking, so empty out the stored 1663 // We're about to cancel active mouse tracking, so empty out the stored
1354 // state. 1664 // state.
1355 active_mouse_tracking_flags_ = 0; 1665 active_mouse_tracking_flags_ = 0;
1356 } else { 1666 } else {
1357 active_mouse_tracking_flags_ = mouse_tracking_flags; 1667 active_mouse_tracking_flags_ = mouse_tracking_flags;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 POINT position = {wr.left, wr.top}; 1828 POINT position = {wr.left, wr.top};
1519 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_.get()); 1829 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_.get());
1520 POINT zero = {0, 0}; 1830 POINT zero = {0, 0};
1521 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; 1831 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA};
1522 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, 1832 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero,
1523 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); 1833 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA);
1524 invalid_rect_.SetRect(0, 0, 0, 0); 1834 invalid_rect_.SetRect(0, 0, 0, 0);
1525 skia::EndPlatformPaint(layered_window_contents_.get()); 1835 skia::EndPlatformPaint(layered_window_contents_.get());
1526 } 1836 }
1527 1837
1838 void NativeWidgetWin::LockUpdates() {
1839 lock_updates_ = true;
1840 saved_window_style_ = GetWindowLong(GWL_STYLE);
1841 SetWindowLong(GWL_STYLE, saved_window_style_ & ~WS_VISIBLE);
1842 }
1843
1844 void NativeWidgetWin::UnlockUpdates() {
1845 SetWindowLong(GWL_STYLE, saved_window_style_);
1846 lock_updates_ = false;
1847 }
1848
1528 void NativeWidgetWin::ClientAreaSizeChanged() { 1849 void NativeWidgetWin::ClientAreaSizeChanged() {
1529 RECT r; 1850 RECT r;
1530 Window* window = GetWidget()->GetContainingWindow(); 1851 Window* window = GetWidget()->GetContainingWindow();
1531 if (IsZoomed() || (window && window->ShouldUseNativeFrame())) 1852 if (IsZoomed() || (window && window->ShouldUseNativeFrame()))
1532 GetClientRect(&r); 1853 GetClientRect(&r);
1533 else 1854 else
1534 GetWindowRect(&r); 1855 GetWindowRect(&r);
1535 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), 1856 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)),
1536 std::max(0, static_cast<int>(r.bottom - r.top))); 1857 std::max(0, static_cast<int>(r.bottom - r.top)));
1537 delegate_->OnSizeChanged(s); 1858 delegate_->OnNativeWidgetSizeChanged(s);
1538 if (use_layered_buffer_) { 1859 if (use_layered_buffer_) {
1539 layered_window_contents_.reset( 1860 layered_window_contents_.reset(
1540 new gfx::CanvasSkia(s.width(), s.height(), false)); 1861 new gfx::CanvasSkia(s.width(), s.height(), false));
1541 } 1862 }
1542 } 1863 }
1543 1864
1544 void NativeWidgetWin::ResetWindowRegion(bool force) { 1865 void NativeWidgetWin::ResetWindowRegion(bool force) {
1545 // A native frame uses the native window region, and we don't want to mess 1866 // A native frame uses the native window region, and we don't want to mess
1546 // with it. 1867 // with it.
1547 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { 1868 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) {
(...skipping 29 matching lines...) Expand all
1577 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { 1898 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
1578 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. 1899 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion.
1579 SetWindowRgn(new_region, TRUE); 1900 SetWindowRgn(new_region, TRUE);
1580 } else { 1901 } else {
1581 DeleteObject(new_region); 1902 DeleteObject(new_region);
1582 } 1903 }
1583 1904
1584 DeleteObject(current_rgn); 1905 DeleteObject(current_rgn);
1585 } 1906 }
1586 1907
1908 LRESULT NativeWidgetWin::CallDefaultNCActivateHandler(BOOL active) {
1909 // The DefWindowProc handling for WM_NCACTIVATE renders the classic-look
1910 // window title bar directly, so we need to use a redraw lock here to prevent
1911 // it from doing so.
1912 ScopedRedrawLock lock(this);
1913 return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0);
1914 }
1915
1587 gfx::AcceleratedWidget NativeWidgetWin::GetAcceleratedWidget() { 1916 gfx::AcceleratedWidget NativeWidgetWin::GetAcceleratedWidget() {
1588 #if defined(VIEWS_COMPOSITOR) 1917 #if defined(VIEWS_COMPOSITOR)
1589 return hwnd(); 1918 return hwnd();
1590 #else 1919 #else
1591 return gfx::kNullAcceleratedWidget; 1920 return gfx::kNullAcceleratedWidget;
1592 #endif 1921 #endif
1593 } 1922 }
1594 1923
1595 void NativeWidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { 1924 void NativeWidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) {
1596 SetMsgHandled(delegate_->OnKeyEvent(key)); 1925 SetMsgHandled(delegate_->OnKeyEvent(key));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 2064
1736 // And now, notify them that they have a brand new parent. 2065 // And now, notify them that they have a brand new parent.
1737 for (NativeWidgets::iterator it = widgets.begin(); 2066 for (NativeWidgets::iterator it = widgets.begin();
1738 it != widgets.end(); ++it) { 2067 it != widgets.end(); ++it) {
1739 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, 2068 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
1740 new_parent); 2069 new_parent);
1741 } 2070 }
1742 } 2071 }
1743 2072
1744 } // namespace views 2073 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/native_widget_win.h ('k') | views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698