| 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 "chrome/browser/renderer_host/render_widget_host_view_win.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 bool RenderWidgetHostViewWin::HasFocus() { | 501 bool RenderWidgetHostViewWin::HasFocus() { |
| 502 return ::GetFocus() == m_hWnd; | 502 return ::GetFocus() == m_hWnd; |
| 503 } | 503 } |
| 504 | 504 |
| 505 void RenderWidgetHostViewWin::Show() { | 505 void RenderWidgetHostViewWin::Show() { |
| 506 DCHECK(parent_hwnd_); | 506 DCHECK(parent_hwnd_); |
| 507 DCHECK(parent_hwnd_ != GetDesktopWindow()); | 507 DCHECK(parent_hwnd_ != GetDesktopWindow()); |
| 508 SetParent(parent_hwnd_); | 508 SetParent(parent_hwnd_); |
| 509 ShowWindow(SW_SHOW); | 509 ShowWindow(SW_SHOW); |
| 510 | 510 |
| 511 // Save away our HWND in the parent window as a property so that the | |
| 512 // accessibility code can find it. | |
| 513 accessibility_prop_.reset(new ViewProp( | |
| 514 GetParent(), | |
| 515 views::kViewsNativeHostPropForAccessibility, | |
| 516 m_hWnd)); | |
| 517 | |
| 518 DidBecomeSelected(); | 511 DidBecomeSelected(); |
| 519 } | 512 } |
| 520 | 513 |
| 521 void RenderWidgetHostViewWin::Hide() { | 514 void RenderWidgetHostViewWin::Hide() { |
| 522 if (GetParent() == GetDesktopWindow()) { | 515 if (GetParent() == GetDesktopWindow()) { |
| 523 LOG(WARNING) << "Hide() called twice in a row: " << this << ":" << | 516 LOG(WARNING) << "Hide() called twice in a row: " << this << ":" << |
| 524 parent_hwnd_ << ":" << GetParent(); | 517 parent_hwnd_ << ":" << GetParent(); |
| 525 return; | 518 return; |
| 526 } | 519 } |
| 527 | 520 |
| 528 accessibility_prop_.reset(); | |
| 529 | |
| 530 if (::GetFocus() == m_hWnd) | 521 if (::GetFocus() == m_hWnd) |
| 531 ::SetFocus(NULL); | 522 ::SetFocus(NULL); |
| 532 ShowWindow(SW_HIDE); | 523 ShowWindow(SW_HIDE); |
| 533 | 524 |
| 534 // Cache the old parent, then orphan the window so we stop receiving messages | 525 // Cache the old parent, then orphan the window so we stop receiving messages |
| 535 parent_hwnd_ = GetParent(); | 526 parent_hwnd_ = GetParent(); |
| 536 SetParent(NULL); | 527 SetParent(NULL); |
| 537 | 528 |
| 538 WasHidden(); | 529 WasHidden(); |
| 539 } | 530 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 770 |
| 780 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { | 771 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { |
| 781 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale | 772 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale |
| 782 // of a browser process. | 773 // of a browser process. |
| 783 OnInputLangChange(0, 0); | 774 OnInputLangChange(0, 0); |
| 784 // Marks that window as supporting mouse-wheel messages rerouting so it is | 775 // Marks that window as supporting mouse-wheel messages rerouting so it is |
| 785 // scrolled when under the mouse pointer even if inactive. | 776 // scrolled when under the mouse pointer even if inactive. |
| 786 props_.push_back(views::SetWindowSupportsRerouteMouseWheel(m_hWnd)); | 777 props_.push_back(views::SetWindowSupportsRerouteMouseWheel(m_hWnd)); |
| 787 props_.push_back(new ViewProp(m_hWnd, kRenderWidgetHostViewKey, | 778 props_.push_back(new ViewProp(m_hWnd, kRenderWidgetHostViewKey, |
| 788 static_cast<RenderWidgetHostView*>(this))); | 779 static_cast<RenderWidgetHostView*>(this))); |
| 789 // Save away our HWND in the parent window as a property so that the | |
| 790 // accessibility code can find it. | |
| 791 accessibility_prop_.reset(new ViewProp( | |
| 792 GetParent(), | |
| 793 views::kViewsNativeHostPropForAccessibility, | |
| 794 m_hWnd)); | |
| 795 | 780 |
| 796 return 0; | 781 return 0; |
| 797 } | 782 } |
| 798 | 783 |
| 799 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, | 784 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, |
| 800 HWND window) { | 785 HWND window) { |
| 801 // If the container is a popup, clicking elsewhere on screen should close the | 786 // If the container is a popup, clicking elsewhere on screen should close the |
| 802 // popup. | 787 // popup. |
| 803 if (close_on_deactivate_ && action == WA_INACTIVE) { | 788 if (close_on_deactivate_ && action == WA_INACTIVE) { |
| 804 // Send a windows message so that any derived classes | 789 // Send a windows message so that any derived classes |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 } | 1605 } |
| 1621 | 1606 |
| 1622 void RenderWidgetHostViewWin::AccessibilityDoDefaultAction(int acc_obj_id) { | 1607 void RenderWidgetHostViewWin::AccessibilityDoDefaultAction(int acc_obj_id) { |
| 1623 if (!render_widget_host_) | 1608 if (!render_widget_host_) |
| 1624 return; | 1609 return; |
| 1625 | 1610 |
| 1626 render_widget_host_->Send(new ViewMsg_AccessibilityDoDefaultAction( | 1611 render_widget_host_->Send(new ViewMsg_AccessibilityDoDefaultAction( |
| 1627 render_widget_host_->routing_id(), acc_obj_id)); | 1612 render_widget_host_->routing_id(), acc_obj_id)); |
| 1628 } | 1613 } |
| 1629 | 1614 |
| 1615 IAccessible* RenderWidgetHostViewWin::GetIAccessible() { |
| 1616 if (render_widget_host_ && !render_widget_host_->renderer_accessible()) { |
| 1617 // Attempt to detect screen readers by sending an event with our custom id. |
| 1618 NotifyWinEvent(EVENT_SYSTEM_ALERT, m_hWnd, kIdCustom, CHILDID_SELF); |
| 1619 } |
| 1620 |
| 1621 if (!browser_accessibility_manager_.get()) { |
| 1622 // Return busy document tree while renderer accessibility tree loads. |
| 1623 webkit_glue::WebAccessibility loading_tree; |
| 1624 loading_tree.role = WebAccessibility::ROLE_DOCUMENT; |
| 1625 loading_tree.state = (1 << WebAccessibility::STATE_BUSY); |
| 1626 browser_accessibility_manager_.reset( |
| 1627 BrowserAccessibilityManager::Create(m_hWnd, loading_tree, this)); |
| 1628 } |
| 1629 |
| 1630 return browser_accessibility_manager_->GetRoot()->toBrowserAccessibilityWin(); |
| 1631 } |
| 1632 |
| 1630 LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, | 1633 LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, |
| 1631 LPARAM lparam, BOOL& handled) { | 1634 LPARAM lparam, BOOL& handled) { |
| 1632 if (kIdCustom == lparam) { | 1635 if (kIdCustom == lparam) { |
| 1633 // An MSAA client requestes our custom id. Assume that we have detected an | 1636 // An MSAA client requestes our custom id. Assume that we have detected an |
| 1634 // active windows screen reader. | 1637 // active windows screen reader. |
| 1635 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); | 1638 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); |
| 1636 render_widget_host_->EnableRendererAccessibility(); | 1639 render_widget_host_->EnableRendererAccessibility(); |
| 1637 | 1640 |
| 1638 // Return with failure. | 1641 // Return with failure. |
| 1639 return static_cast<LRESULT>(0L); | 1642 return static_cast<LRESULT>(0L); |
| 1640 } | 1643 } |
| 1641 | 1644 |
| 1642 if (lparam != OBJID_CLIENT) { | 1645 if (lparam != OBJID_CLIENT) { |
| 1643 handled = false; | 1646 handled = false; |
| 1644 return static_cast<LRESULT>(0L); | 1647 return static_cast<LRESULT>(0L); |
| 1645 } | 1648 } |
| 1646 | 1649 |
| 1647 if (render_widget_host_ && !render_widget_host_->renderer_accessible()) { | 1650 IAccessible* iaccessible = GetIAccessible(); |
| 1648 // Attempt to detect screen readers by sending an event with our custom id. | 1651 if (iaccessible) |
| 1649 NotifyWinEvent(EVENT_SYSTEM_ALERT, m_hWnd, kIdCustom, CHILDID_SELF); | 1652 return LresultFromObject(IID_IAccessible, wparam, iaccessible); |
| 1650 } | |
| 1651 | |
| 1652 if (!browser_accessibility_manager_.get()) { | |
| 1653 // Return busy document tree while renderer accessibility tree loads. | |
| 1654 webkit_glue::WebAccessibility loading_tree; | |
| 1655 loading_tree.role = WebAccessibility::ROLE_DOCUMENT; | |
| 1656 loading_tree.state = (1 << WebAccessibility::STATE_BUSY); | |
| 1657 browser_accessibility_manager_.reset( | |
| 1658 BrowserAccessibilityManager::Create(m_hWnd, loading_tree, this)); | |
| 1659 } | |
| 1660 | |
| 1661 base::win::ScopedComPtr<IAccessible> root( | |
| 1662 browser_accessibility_manager_->GetRoot()->toBrowserAccessibilityWin()); | |
| 1663 if (root.get()) | |
| 1664 return LresultFromObject(IID_IAccessible, wparam, root.Detach()); | |
| 1665 | 1653 |
| 1666 handled = false; | 1654 handled = false; |
| 1667 return static_cast<LRESULT>(0L); | 1655 return static_cast<LRESULT>(0L); |
| 1668 } | 1656 } |
| 1669 | 1657 |
| 1670 LRESULT RenderWidgetHostViewWin::OnParentNotify(UINT message, WPARAM wparam, | 1658 LRESULT RenderWidgetHostViewWin::OnParentNotify(UINT message, WPARAM wparam, |
| 1671 LPARAM lparam, BOOL& handled) { | 1659 LPARAM lparam, BOOL& handled) { |
| 1672 handled = FALSE; | 1660 handled = FALSE; |
| 1673 | 1661 |
| 1674 if (!render_widget_host_) | 1662 if (!render_widget_host_) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 } | 1791 } |
| 1804 | 1792 |
| 1805 // static | 1793 // static |
| 1806 RenderWidgetHostView* | 1794 RenderWidgetHostView* |
| 1807 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1795 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 1808 gfx::NativeView native_view) { | 1796 gfx::NativeView native_view) { |
| 1809 return ::IsWindow(native_view) ? | 1797 return ::IsWindow(native_view) ? |
| 1810 reinterpret_cast<RenderWidgetHostView*>( | 1798 reinterpret_cast<RenderWidgetHostView*>( |
| 1811 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; | 1799 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; |
| 1812 } | 1800 } |
| OLD | NEW |