OLD | NEW |
---|---|
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 #include <shellapi.h> | 8 #include <shellapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate) | 373 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate) |
374 : delegate_(delegate), | 374 : delegate_(delegate), |
375 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 375 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
376 active_mouse_tracking_flags_(0), | 376 active_mouse_tracking_flags_(0), |
377 use_layered_buffer_(false), | 377 use_layered_buffer_(false), |
378 layered_alpha_(255), | 378 layered_alpha_(255), |
379 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), | 379 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), |
380 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 380 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
381 can_update_layered_window_(true), | 381 can_update_layered_window_(true), |
382 restore_focus_when_enabled_(false), | 382 restore_focus_when_enabled_(false), |
383 accessibility_view_events_index_(-1), | |
384 accessibility_view_events_(kMaxAccessibilityViewEvents), | |
385 previous_cursor_(NULL), | 383 previous_cursor_(NULL), |
386 fullscreen_(false), | 384 fullscreen_(false), |
387 force_hidden_count_(0), | 385 force_hidden_count_(0), |
388 lock_updates_count_(0), | 386 lock_updates_count_(0), |
389 saved_window_style_(0), | 387 saved_window_style_(0), |
390 ignore_window_pos_changes_(false), | 388 ignore_window_pos_changes_(false), |
391 ALLOW_THIS_IN_INITIALIZER_LIST(ignore_pos_changes_factory_(this)), | 389 ALLOW_THIS_IN_INITIALIZER_LIST(ignore_pos_changes_factory_(this)), |
392 last_monitor_(NULL), | 390 last_monitor_(NULL), |
393 is_right_mouse_pressed_on_caption_(false), | 391 is_right_mouse_pressed_on_caption_(false), |
394 restored_enabled_(false), | 392 restored_enabled_(false), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 // We need to explicitly activate the window if we've been shown with a state | 438 // We need to explicitly activate the window if we've been shown with a state |
441 // that should activate, because if we're opened from a desktop shortcut while | 439 // that should activate, because if we're opened from a desktop shortcut while |
442 // an existing window is already running it doesn't seem to be enough to use | 440 // an existing window is already running it doesn't seem to be enough to use |
443 // one of these flags to activate the window. | 441 // one of these flags to activate the window. |
444 if (show_state == SW_SHOWNORMAL || show_state == SW_SHOWMAXIMIZED) | 442 if (show_state == SW_SHOWNORMAL || show_state == SW_SHOWMAXIMIZED) |
445 Activate(); | 443 Activate(); |
446 | 444 |
447 SetInitialFocus(); | 445 SetInitialFocus(); |
448 } | 446 } |
449 | 447 |
450 View* NativeWidgetWin::GetAccessibilityViewEventAt(int id) { | 448 View* NativeWidgetWin::GetAccessibilityViewFromChildId(long child_id) { |
451 // Convert from MSAA child id. | 449 long unique_id = -child_id; |
sky
2011/10/25 20:08:45
Why do you negate this?
dmazzoni
2011/10/26 16:46:13
It's explained in SendNativeAccessibilityEvent; I
| |
452 id = -(id + 1); | 450 base::hash_map<long, View*>::iterator iter = |
453 DCHECK(id >= 0 && id < kMaxAccessibilityViewEvents); | 451 accessibility_id_view_map_.find(unique_id); |
454 return accessibility_view_events_[id]; | 452 if (iter != accessibility_id_view_map_.end()) |
sky
2011/10/25 20:08:45
nit: convert to a return statement.
| |
455 } | 453 return iter->second; |
456 | 454 else |
457 int NativeWidgetWin::AddAccessibilityViewEvent(View* view) { | 455 return NULL; |
458 accessibility_view_events_index_ = | |
459 (accessibility_view_events_index_ + 1) % kMaxAccessibilityViewEvents; | |
460 accessibility_view_events_[accessibility_view_events_index_] = view; | |
461 | |
462 // Convert to MSAA child id. | |
463 return -(accessibility_view_events_index_ + 1); | |
464 } | |
465 | |
466 void NativeWidgetWin::ClearAccessibilityViewEvent(View* view) { | |
467 for (std::vector<View*>::iterator it = accessibility_view_events_.begin(); | |
468 it != accessibility_view_events_.end(); | |
469 ++it) { | |
470 if (*it == view) | |
471 *it = NULL; | |
472 } | |
473 } | 456 } |
474 | 457 |
475 void NativeWidgetWin::PushForceHidden() { | 458 void NativeWidgetWin::PushForceHidden() { |
476 if (force_hidden_count_++ == 0) | 459 if (force_hidden_count_++ == 0) |
477 Hide(); | 460 Hide(); |
478 } | 461 } |
479 | 462 |
480 void NativeWidgetWin::PopForceHidden() { | 463 void NativeWidgetWin::PopForceHidden() { |
481 if (--force_hidden_count_ <= 0) { | 464 if (--force_hidden_count_ <= 0) { |
482 force_hidden_count_ = 0; | 465 force_hidden_count_ = 0; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 } | 564 } |
582 | 565 |
583 void NativeWidgetWin::CalculateOffsetToAncestorWithLayer( | 566 void NativeWidgetWin::CalculateOffsetToAncestorWithLayer( |
584 gfx::Point* offset, | 567 gfx::Point* offset, |
585 ui::Layer** layer_parent) { | 568 ui::Layer** layer_parent) { |
586 } | 569 } |
587 | 570 |
588 void NativeWidgetWin::ReorderLayers() { | 571 void NativeWidgetWin::ReorderLayers() { |
589 } | 572 } |
590 | 573 |
591 void NativeWidgetWin::ViewRemoved(View* view) { | 574 void NativeWidgetWin::ViewRemoved(View* view) { |
sky
2011/10/25 20:08:45
Don't you need to do this for all descendants of v
dmazzoni
2011/10/26 16:46:13
Doesn't apply anymore now that we search.
| |
592 if (drop_target_.get()) | 575 if (drop_target_.get()) |
593 drop_target_->ResetTargetViewIfEquals(view); | 576 drop_target_->ResetTargetViewIfEquals(view); |
594 | 577 |
595 ClearAccessibilityViewEvent(view); | 578 // Remove this view from the map from accessibility unique IDs to views. |
579 IAccessible* accessible = view->GetNativeViewAccessible(); | |
580 IAccessible2* accessible2 = NULL; | |
581 HRESULT hr = accessible->QueryInterface( | |
sky
2011/10/25 20:08:45
How expensive is this? Would it be better to maint
dmazzoni
2011/10/26 16:46:13
It couldn't be that expensive - it's called thousa
| |
582 IID_IAccessible2, reinterpret_cast<void**>(&accessible2)); | |
583 if (hr == S_OK) { | |
584 long unique_id; | |
585 hr = accessible2->get_uniqueID(&unique_id); | |
586 if (hr == S_OK) { | |
sky
2011/10/25 20:08:45
nit: no {}
| |
587 accessibility_id_view_map_.erase(unique_id); | |
588 } | |
589 } | |
596 } | 590 } |
597 | 591 |
598 void NativeWidgetWin::SetNativeWindowProperty(const char* name, void* value) { | 592 void NativeWidgetWin::SetNativeWindowProperty(const char* name, void* value) { |
599 // Remove the existing property (if any). | 593 // Remove the existing property (if any). |
600 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { | 594 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { |
601 if ((*i)->Key() == name) { | 595 if ((*i)->Key() == name) { |
602 props_.erase(i); | 596 props_.erase(i); |
603 break; | 597 break; |
604 } | 598 } |
605 } | 599 } |
(...skipping 10 matching lines...) Expand all Loading... | |
616 return tooltip_manager_.get(); | 610 return tooltip_manager_.get(); |
617 } | 611 } |
618 | 612 |
619 bool NativeWidgetWin::IsScreenReaderActive() const { | 613 bool NativeWidgetWin::IsScreenReaderActive() const { |
620 return screen_reader_active_; | 614 return screen_reader_active_; |
621 } | 615 } |
622 | 616 |
623 void NativeWidgetWin::SendNativeAccessibilityEvent( | 617 void NativeWidgetWin::SendNativeAccessibilityEvent( |
624 View* view, | 618 View* view, |
625 ui::AccessibilityTypes::Event event_type) { | 619 ui::AccessibilityTypes::Event event_type) { |
626 // Now call the Windows-specific method to notify MSAA clients of this | 620 DWORD native_event = NativeViewAccessibilityWin::MSAAEvent(event_type); |
627 // event. The widget gives us a temporary unique child ID to associate | 621 gfx::NativeView native_view = this->GetNativeView(); |
628 // with this view so that clients can call get_accChild in | 622 |
629 // NativeViewAccessibilityWin to retrieve the IAccessible associated | 623 // Get the unique ID from the view's IAccessible2 interface. |
630 // with this view. | 624 IAccessible* accessible = view->GetNativeViewAccessible(); |
631 int child_id = AddAccessibilityViewEvent(view); | 625 IAccessible2* accessible2 = NULL; |
632 ::NotifyWinEvent(NativeViewAccessibilityWin::MSAAEvent(event_type), | 626 HRESULT hr = accessible->QueryInterface( |
633 GetNativeView(), OBJID_CLIENT, child_id); | 627 IID_IAccessible2, reinterpret_cast<void**>(&accessible2)); |
628 if (hr != S_OK) { | |
629 // If this is reached, you're probably trying to fire a notification on a | |
630 // views::NativeViewHost that has only a default IAccessible. You have to | |
631 // either call ::NotifyWinEvent directly, or override | |
632 // GetNativeViewAccessible for that view. | |
633 NOTREACHED(); | |
634 return; | |
635 } | |
636 long unique_id; | |
637 hr = accessible2->get_uniqueID(&unique_id); | |
638 DCHECK_EQ(hr, S_OK); | |
639 if (!accessibility_id_view_map_[unique_id]) | |
sky
2011/10/25 20:08:45
Can you reset the map all the time? Or maybe DCHEC
| |
640 accessibility_id_view_map_[unique_id] = view; | |
641 | |
642 // Send the negation of the unique id as the child id parameter to | |
643 // NotifyWinEvent. The client will call get_accChild on the top-level | |
644 // NativeViewAccessibilityWin object, where positive child ids are | |
645 // interpreted as 1-based child indices, and negative child ids are | |
646 // interpreted as unique ids. | |
647 ::NotifyWinEvent(native_event, native_view, OBJID_CLIENT, -unique_id); | |
634 } | 648 } |
635 | 649 |
636 void NativeWidgetWin::SetMouseCapture() { | 650 void NativeWidgetWin::SetMouseCapture() { |
637 DCHECK(!HasMouseCapture()); | 651 DCHECK(!HasMouseCapture()); |
638 SetCapture(hwnd()); | 652 SetCapture(hwnd()); |
639 } | 653 } |
640 | 654 |
641 void NativeWidgetWin::ReleaseMouseCapture() { | 655 void NativeWidgetWin::ReleaseMouseCapture() { |
642 ReleaseCapture(); | 656 ReleaseCapture(); |
643 } | 657 } |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2625 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2639 return (GetKeyState(VK_LBUTTON) & 0x80) || |
2626 (GetKeyState(VK_RBUTTON) & 0x80) || | 2640 (GetKeyState(VK_RBUTTON) & 0x80) || |
2627 (GetKeyState(VK_MBUTTON) & 0x80) || | 2641 (GetKeyState(VK_MBUTTON) & 0x80) || |
2628 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2642 (GetKeyState(VK_XBUTTON1) & 0x80) || |
2629 (GetKeyState(VK_XBUTTON2) & 0x80); | 2643 (GetKeyState(VK_XBUTTON2) & 0x80); |
2630 } | 2644 } |
2631 | 2645 |
2632 } // namespace internal | 2646 } // namespace internal |
2633 | 2647 |
2634 } // namespace views | 2648 } // namespace views |
OLD | NEW |