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

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

Issue 6487002: Add a new constructor to KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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/widget_win.h ('k') | no next file » | 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/widget_win.h" 5 #include "views/widget/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/win/windows_version.h" 10 #include "base/win/windows_version.h"
11 #include "ui/base/keycodes/keyboard_code_conversion_win.h" 11 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
12 #include "ui/base/l10n/l10n_util_win.h" 12 #include "ui/base/l10n/l10n_util_win.h"
13 #include "ui/base/system_monitor/system_monitor.h" 13 #include "ui/base/system_monitor/system_monitor.h"
14 #include "ui/base/theme_provider.h" 14 #include "ui/base/theme_provider.h"
15 #include "ui/base/view_prop.h" 15 #include "ui/base/view_prop.h"
16 #include "ui/base/win/hwnd_util.h" 16 #include "ui/base/win/hwnd_util.h"
17 #include "ui/gfx/canvas_skia.h" 17 #include "ui/gfx/canvas_skia.h"
18 #include "ui/gfx/native_theme_win.h" 18 #include "ui/gfx/native_theme_win.h"
19 #include "ui/gfx/path.h" 19 #include "ui/gfx/path.h"
20 #include "views/accessibility/view_accessibility.h" 20 #include "views/accessibility/view_accessibility.h"
21 #include "views/controls/native_control_win.h" 21 #include "views/controls/native_control_win.h"
22 #include "views/focus/accelerator_handler.h"
22 #include "views/focus/focus_util_win.h" 23 #include "views/focus/focus_util_win.h"
23 #include "views/views_delegate.h" 24 #include "views/views_delegate.h"
24 #include "views/widget/aero_tooltip_manager.h" 25 #include "views/widget/aero_tooltip_manager.h"
25 #include "views/widget/child_window_message_processor.h" 26 #include "views/widget/child_window_message_processor.h"
26 #include "views/widget/default_theme_provider.h" 27 #include "views/widget/default_theme_provider.h"
27 #include "views/widget/drop_target_win.h" 28 #include "views/widget/drop_target_win.h"
28 #include "views/widget/root_view.h" 29 #include "views/widget/root_view.h"
29 #include "views/widget/widget_delegate.h" 30 #include "views/widget/widget_delegate.h"
30 #include "views/widget/widget_utils.h" 31 #include "views/widget/widget_utils.h"
31 #include "views/window/window_win.h" 32 #include "views/window/window_win.h"
32 33
33 #pragma comment(lib, "dwmapi.lib") 34 #pragma comment(lib, "dwmapi.lib")
34 35
35 using ui::ViewProp; 36 using ui::ViewProp;
36 37
37 namespace { 38 namespace {
38 39
39 // Returns whether the specified window is the current active window. 40 // Returns whether the specified window is the current active window.
40 bool IsWindowActive(HWND hwnd) { 41 bool IsWindowActive(HWND hwnd) {
41 WINDOWINFO info; 42 WINDOWINFO info;
42 return ::GetWindowInfo(hwnd, &info) && 43 return ::GetWindowInfo(hwnd, &info) &&
43 ((info.dwWindowStatus & WS_ACTIVECAPTION) != 0); 44 ((info.dwWindowStatus & WS_ACTIVECAPTION) != 0);
44 } 45 }
45 46
46 } // namespace 47 } // namespace
47 48
48 namespace views { 49 namespace views {
49 50
51 // A singleton object that keeps track of the current message.
52 class CurrentMessageWatcher : public MessageLoopForUI::Observer {
53 public:
54 CurrentMessageWatcher() {
55 MessageLoopForUI::current()->AddObserver(this);
56 }
57 virtual ~CurrentMessageWatcher() {
58 }
59
60 const MSG& current_message() const { return current_messages_.back(); }
61
62 private:
63 // Overridden from MessageLoop::Observer:
64 void WillProcessMessage(const MSG& msg) {
65 current_messages_.push_back(msg);
66 }
67 virtual void DidProcessMessage(const MSG& msg) {
68 current_messages_.pop_back();
69 }
70
71 std::vector<MSG> current_messages_;
72
73 DISALLOW_COPY_AND_ASSIGN(CurrentMessageWatcher);
74 };
75
50 // Property used to link the HWND to its RootView. 76 // Property used to link the HWND to its RootView.
51 static const char* const kRootViewWindowProperty = "__ROOT_VIEW__"; 77 static const char* const kRootViewWindowProperty = "__ROOT_VIEW__";
52 78
53 // Links the HWND to it's Widget (as a Widget, not a WidgetWin). 79 // Links the HWND to it's Widget (as a Widget, not a WidgetWin).
54 static const char* const kWidgetKey = "__VIEWS_WIDGET__"; 80 static const char* const kWidgetKey = "__VIEWS_WIDGET__";
55 81
82 // static
56 bool WidgetWin::screen_reader_active_ = false; 83 bool WidgetWin::screen_reader_active_ = false;
57 84
85 // static
86 CurrentMessageWatcher* WidgetWin::message_watcher_ = NULL;
87
58 // A custom MSAA object id used to determine if a screen reader is actively 88 // A custom MSAA object id used to determine if a screen reader is actively
59 // listening for MSAA events. 89 // listening for MSAA events.
60 #define OBJID_CUSTOM 1 90 #define OBJID_CUSTOM 1
61 91
62 RootView* GetRootViewForHWND(HWND hwnd) { 92 RootView* GetRootViewForHWND(HWND hwnd) {
63 return reinterpret_cast<RootView*>( 93 return reinterpret_cast<RootView*>(
64 ViewProp::GetValue(hwnd, kRootViewWindowProperty)); 94 ViewProp::GetValue(hwnd, kRootViewWindowProperty));
65 } 95 }
66 96
67 /////////////////////////////////////////////////////////////////////////////// 97 ///////////////////////////////////////////////////////////////////////////////
68 // WidgetWin, public 98 // WidgetWin, public
69 99
70 WidgetWin::WidgetWin() 100 WidgetWin::WidgetWin()
71 : close_widget_factory_(this), 101 : close_widget_factory_(this),
72 active_mouse_tracking_flags_(0), 102 active_mouse_tracking_flags_(0),
73 has_capture_(false), 103 has_capture_(false),
74 use_layered_buffer_(true), 104 use_layered_buffer_(true),
75 layered_alpha_(255), 105 layered_alpha_(255),
76 delete_on_destroy_(true), 106 delete_on_destroy_(true),
77 can_update_layered_window_(true), 107 can_update_layered_window_(true),
78 last_mouse_event_was_move_(false), 108 last_mouse_event_was_move_(false),
79 is_mouse_down_(false), 109 is_mouse_down_(false),
80 is_window_(false), 110 is_window_(false),
81 restore_focus_when_enabled_(false), 111 restore_focus_when_enabled_(false),
82 delegate_(NULL), 112 delegate_(NULL),
83 accessibility_view_events_index_(-1), 113 accessibility_view_events_index_(-1),
84 accessibility_view_events_(kMaxAccessibilityViewEvents) { 114 accessibility_view_events_(kMaxAccessibilityViewEvents) {
115 if (!message_watcher_)
116 message_watcher_ = new CurrentMessageWatcher;
85 } 117 }
86 118
87 WidgetWin::~WidgetWin() { 119 WidgetWin::~WidgetWin() {
88 } 120 }
89 121
90 // static 122 // static
91 WidgetWin* WidgetWin::GetWidget(HWND hwnd) { 123 WidgetWin* WidgetWin::GetWidget(HWND hwnd) {
92 // TODO(jcivelli): http://crbug.com/44499 We need a way to test that hwnd is 124 // TODO(jcivelli): http://crbug.com/44499 We need a way to test that hwnd is
93 // associated with a WidgetWin (it might be a pure 125 // associated with a WidgetWin (it might be a pure
94 // WindowImpl). 126 // WindowImpl).
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 return GetRootView()->ContainsNativeView(native_view); 549 return GetRootView()->ContainsNativeView(native_view);
518 } 550 }
519 551
520 //////////////////////////////////////////////////////////////////////////////// 552 ////////////////////////////////////////////////////////////////////////////////
521 // MessageLoop::Observer 553 // MessageLoop::Observer
522 554
523 void WidgetWin::WillProcessMessage(const MSG& msg) { 555 void WidgetWin::WillProcessMessage(const MSG& msg) {
524 } 556 }
525 557
526 void WidgetWin::DidProcessMessage(const MSG& msg) { 558 void WidgetWin::DidProcessMessage(const MSG& msg) {
527 if (root_view_->NeedsPainting(true)) { 559 if (root_view_->NeedsPainting(true))
528 PaintNow(root_view_->GetScheduledPaintRect()); 560 PaintNow(root_view_->GetScheduledPaintRect());
529 }
530 } 561 }
531 562
532 //////////////////////////////////////////////////////////////////////////////// 563 ////////////////////////////////////////////////////////////////////////////////
533 // FocusTraversable 564 // FocusTraversable
534 565
535 FocusSearch* WidgetWin::GetFocusSearch() { 566 FocusSearch* WidgetWin::GetFocusSearch() {
536 return root_view_->GetFocusSearch(); 567 return root_view_->GetFocusSearch();
537 } 568 }
538 569
539 FocusTraversable* WidgetWin::GetFocusTraversableParent() { 570 FocusTraversable* WidgetWin::GetFocusTraversableParent() {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 SetMsgHandled(FALSE); 713 SetMsgHandled(FALSE);
683 } 714 }
684 715
685 void WidgetWin::OnInitMenuPopup(HMENU menu, 716 void WidgetWin::OnInitMenuPopup(HMENU menu,
686 UINT position, 717 UINT position,
687 BOOL is_system_menu) { 718 BOOL is_system_menu) {
688 SetMsgHandled(FALSE); 719 SetMsgHandled(FALSE);
689 } 720 }
690 721
691 void WidgetWin::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) { 722 void WidgetWin::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) {
692 KeyEvent event(ui::ET_KEY_PRESSED, ui::KeyboardCodeForWindowsKeyCode(c), 723 KeyEvent event(message_watcher_->current_message());
693 KeyEvent::GetKeyStateFlags(), rep_cnt, flags,
694 WM_KEYDOWN);
695 RootView* root_view = GetFocusedViewRootView(); 724 RootView* root_view = GetFocusedViewRootView();
696 if (!root_view) 725 if (!root_view)
697 root_view = root_view_.get(); 726 root_view = root_view_.get();
698 727
699 SetMsgHandled(root_view->ProcessKeyEvent(event)); 728 SetMsgHandled(root_view->ProcessKeyEvent(event));
700 } 729 }
701 730
702 void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) { 731 void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) {
703 KeyEvent event(ui::ET_KEY_RELEASED, ui::KeyboardCodeForWindowsKeyCode(c), 732 KeyEvent event(message_watcher_->current_message());
704 KeyEvent::GetKeyStateFlags(), rep_cnt, flags,
705 WM_KEYUP);
706 RootView* root_view = GetFocusedViewRootView(); 733 RootView* root_view = GetFocusedViewRootView();
707 if (!root_view) 734 if (!root_view)
708 root_view = root_view_.get(); 735 root_view = root_view_.get();
709 736
710 SetMsgHandled(root_view->ProcessKeyEvent(event)); 737 SetMsgHandled(root_view->ProcessKeyEvent(event));
711 } 738 }
712 739
713 void WidgetWin::OnKillFocus(HWND focused_window) { 740 void WidgetWin::OnKillFocus(HWND focused_window) {
714 GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( 741 GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent(
715 this->GetNativeView(), 742 this->GetNativeView(),
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { 1412 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) {
1386 return Widget::GetWidgetFromNativeView(native_window); 1413 return Widget::GetWidgetFromNativeView(native_window);
1387 } 1414 }
1388 1415
1389 // static 1416 // static
1390 void Widget::NotifyLocaleChanged() { 1417 void Widget::NotifyLocaleChanged() {
1391 NOTIMPLEMENTED(); 1418 NOTIMPLEMENTED();
1392 } 1419 }
1393 1420
1394 } // namespace views 1421 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/widget_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698