| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 662 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
| 663 | 663 |
| 664 if (legacy_render_widget_host_HWND_) | 664 if (legacy_render_widget_host_HWND_) |
| 665 legacy_render_widget_host_HWND_->Show(); | 665 legacy_render_widget_host_HWND_->Show(); |
| 666 #endif | 666 #endif |
| 667 } | 667 } |
| 668 | 668 |
| 669 void RenderWidgetHostViewAura::Hide() { | 669 void RenderWidgetHostViewAura::Hide() { |
| 670 window_->Hide(); | 670 window_->Hide(); |
| 671 | 671 |
| 672 // TODO(wjmaclean): can host_ ever be null? |
| 672 if (host_ && !host_->is_hidden()) { | 673 if (host_ && !host_->is_hidden()) { |
| 673 host_->WasHidden(); | 674 host_->WasHidden(); |
| 674 delegated_frame_host_->WasHidden(); | 675 delegated_frame_host_->WasHidden(); |
| 675 | 676 |
| 676 #if defined(OS_WIN) | 677 #if defined(OS_WIN) |
| 677 constrained_rects_.clear(); | 678 constrained_rects_.clear(); |
| 678 aura::WindowTreeHost* host = window_->GetHost(); | 679 aura::WindowTreeHost* host = window_->GetHost(); |
| 679 if (host) { | 680 if (host) { |
| 680 HWND parent = host->GetAcceleratedWidget(); | 681 HWND parent = host->GetAcceleratedWidget(); |
| 681 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 682 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 #if defined(OS_WIN) | 769 #if defined(OS_WIN) |
| 769 if (CanFocus()) { | 770 if (CanFocus()) { |
| 770 aura::WindowTreeHost* host = window_->GetHost(); | 771 aura::WindowTreeHost* host = window_->GetHost(); |
| 771 if (host) { | 772 if (host) { |
| 772 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); | 773 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); |
| 773 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) | 774 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) |
| 774 ::SetFocus(hwnd); | 775 ::SetFocus(hwnd); |
| 775 } | 776 } |
| 776 } | 777 } |
| 777 #endif | 778 #endif |
| 779 // TODO(wjmaclean): can host_ ever be null? |
| 778 if (host_ && set_focus_on_mouse_down_or_key_event_) { | 780 if (host_ && set_focus_on_mouse_down_or_key_event_) { |
| 779 set_focus_on_mouse_down_or_key_event_ = false; | 781 set_focus_on_mouse_down_or_key_event_ = false; |
| 780 host_->Focus(); | 782 host_->Focus(); |
| 781 } | 783 } |
| 782 } | 784 } |
| 783 | 785 |
| 784 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { | 786 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { |
| 785 RenderViewHost* rvh = RenderViewHost::From(host_); | 787 RenderViewHost* rvh = RenderViewHost::From(host_); |
| 786 if (!rvh) | 788 if (!rvh) |
| 787 return nullptr; | 789 return nullptr; |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 cursor_client->ShowCursor(); | 1592 cursor_client->ShowCursor(); |
| 1591 } | 1593 } |
| 1592 | 1594 |
| 1593 host_->LostMouseLock(); | 1595 host_->LostMouseLock(); |
| 1594 } | 1596 } |
| 1595 | 1597 |
| 1596 //////////////////////////////////////////////////////////////////////////////// | 1598 //////////////////////////////////////////////////////////////////////////////// |
| 1597 // RenderWidgetHostViewAura, ui::TextInputClient implementation: | 1599 // RenderWidgetHostViewAura, ui::TextInputClient implementation: |
| 1598 void RenderWidgetHostViewAura::SetCompositionText( | 1600 void RenderWidgetHostViewAura::SetCompositionText( |
| 1599 const ui::CompositionText& composition) { | 1601 const ui::CompositionText& composition) { |
| 1602 // TODO(wjmaclean): can host_ ever be null? |
| 1600 if (!host_) | 1603 if (!host_) |
| 1601 return; | 1604 return; |
| 1602 | 1605 |
| 1603 // TODO(suzhe): convert both renderer_host and renderer to use | 1606 // TODO(suzhe): convert both renderer_host and renderer to use |
| 1604 // ui::CompositionText. | 1607 // ui::CompositionText. |
| 1605 std::vector<blink::WebCompositionUnderline> underlines; | 1608 std::vector<blink::WebCompositionUnderline> underlines; |
| 1606 underlines.reserve(composition.underlines.size()); | 1609 underlines.reserve(composition.underlines.size()); |
| 1607 for (std::vector<ui::CompositionUnderline>::const_iterator it = | 1610 for (std::vector<ui::CompositionUnderline>::const_iterator it = |
| 1608 composition.underlines.begin(); | 1611 composition.underlines.begin(); |
| 1609 it != composition.underlines.end(); ++it) { | 1612 it != composition.underlines.end(); ++it) { |
| 1610 underlines.push_back( | 1613 underlines.push_back( |
| 1611 blink::WebCompositionUnderline(static_cast<unsigned>(it->start_offset), | 1614 blink::WebCompositionUnderline(static_cast<unsigned>(it->start_offset), |
| 1612 static_cast<unsigned>(it->end_offset), | 1615 static_cast<unsigned>(it->end_offset), |
| 1613 it->color, | 1616 it->color, |
| 1614 it->thick, | 1617 it->thick, |
| 1615 it->background_color)); | 1618 it->background_color)); |
| 1616 } | 1619 } |
| 1617 | 1620 |
| 1618 // TODO(suzhe): due to a bug of webkit, we can't use selection range with | 1621 // TODO(suzhe): due to a bug of webkit, we can't use selection range with |
| 1619 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788 | 1622 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788 |
| 1620 host_->ImeSetComposition(composition.text, underlines, | 1623 host_->ImeSetComposition(composition.text, underlines, |
| 1621 gfx::Range::InvalidRange(), | 1624 gfx::Range::InvalidRange(), |
| 1622 composition.selection.end(), | 1625 composition.selection.end(), |
| 1623 composition.selection.end()); | 1626 composition.selection.end()); |
| 1624 | 1627 |
| 1625 has_composition_text_ = !composition.text.empty(); | 1628 has_composition_text_ = !composition.text.empty(); |
| 1626 } | 1629 } |
| 1627 | 1630 |
| 1628 void RenderWidgetHostViewAura::ConfirmCompositionText() { | 1631 void RenderWidgetHostViewAura::ConfirmCompositionText() { |
| 1632 // TODO(wjmaclean): can host_ ever be null? |
| 1629 if (host_ && has_composition_text_) { | 1633 if (host_ && has_composition_text_) { |
| 1630 host_->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), | 1634 host_->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), |
| 1631 false); | 1635 false); |
| 1632 } | 1636 } |
| 1633 has_composition_text_ = false; | 1637 has_composition_text_ = false; |
| 1634 } | 1638 } |
| 1635 | 1639 |
| 1636 void RenderWidgetHostViewAura::ClearCompositionText() { | 1640 void RenderWidgetHostViewAura::ClearCompositionText() { |
| 1641 // TODO(wjmaclean): can host_ ever be null? |
| 1637 if (host_ && has_composition_text_) | 1642 if (host_ && has_composition_text_) |
| 1638 host_->ImeCancelComposition(); | 1643 host_->ImeCancelComposition(); |
| 1639 has_composition_text_ = false; | 1644 has_composition_text_ = false; |
| 1640 } | 1645 } |
| 1641 | 1646 |
| 1642 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { | 1647 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
| 1643 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); | 1648 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); |
| 1649 // TODO(wjmaclean): can host_ ever be null? |
| 1644 if (host_) | 1650 if (host_) |
| 1645 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); | 1651 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
| 1646 has_composition_text_ = false; | 1652 has_composition_text_ = false; |
| 1647 } | 1653 } |
| 1648 | 1654 |
| 1649 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1655 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
| 1650 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1656 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
| 1651 popup_child_host_view_->InsertChar(event); | 1657 popup_child_host_view_->InsertChar(event); |
| 1652 return; | 1658 return; |
| 1653 } | 1659 } |
| 1654 | 1660 |
| 1655 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1661 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
| 1662 // TODO(wjmaclean): can host_ ever be null? |
| 1656 if (host_ && | 1663 if (host_ && |
| 1657 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1664 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { |
| 1658 // Send a blink::WebInputEvent::Char event to |host_|. | 1665 // Send a blink::WebInputEvent::Char event to |host_|. |
| 1659 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1666 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
| 1660 } | 1667 } |
| 1661 } | 1668 } |
| 1662 | 1669 |
| 1663 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1670 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
| 1664 return text_input_type_; | 1671 return text_input_type_; |
| 1665 } | 1672 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 *text = selection_text_; | 1788 *text = selection_text_; |
| 1782 } else { | 1789 } else { |
| 1783 *text = selection_text_.substr( | 1790 *text = selection_text_.substr( |
| 1784 range.GetMin() - selection_text_offset_, | 1791 range.GetMin() - selection_text_offset_, |
| 1785 range.length()); | 1792 range.length()); |
| 1786 } | 1793 } |
| 1787 return true; | 1794 return true; |
| 1788 } | 1795 } |
| 1789 | 1796 |
| 1790 void RenderWidgetHostViewAura::OnInputMethodChanged() { | 1797 void RenderWidgetHostViewAura::OnInputMethodChanged() { |
| 1798 // TODO(wjmaclean): can host_ ever be null? |
| 1791 if (!host_) | 1799 if (!host_) |
| 1792 return; | 1800 return; |
| 1793 | 1801 |
| 1794 // TODO(suzhe): implement the newly added “locale” property of HTML DOM | 1802 // TODO(suzhe): implement the newly added “locale” property of HTML DOM |
| 1795 // TextEvent. | 1803 // TextEvent. |
| 1796 } | 1804 } |
| 1797 | 1805 |
| 1798 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment( | 1806 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment( |
| 1799 base::i18n::TextDirection direction) { | 1807 base::i18n::TextDirection direction) { |
| 1808 // TODO(wjmaclean): can host_ ever be null? |
| 1800 if (!host_) | 1809 if (!host_) |
| 1801 return false; | 1810 return false; |
| 1802 host_->UpdateTextDirection( | 1811 host_->UpdateTextDirection( |
| 1803 direction == base::i18n::RIGHT_TO_LEFT ? | 1812 direction == base::i18n::RIGHT_TO_LEFT ? |
| 1804 blink::WebTextDirectionRightToLeft : | 1813 blink::WebTextDirectionRightToLeft : |
| 1805 blink::WebTextDirectionLeftToRight); | 1814 blink::WebTextDirectionLeftToRight); |
| 1806 host_->NotifyTextDirection(); | 1815 host_->NotifyTextDirection(); |
| 1807 return true; | 1816 return true; |
| 1808 } | 1817 } |
| 1809 | 1818 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 void RenderWidgetHostViewAura::OnCaptureLost() { | 1912 void RenderWidgetHostViewAura::OnCaptureLost() { |
| 1904 host_->LostCapture(); | 1913 host_->LostCapture(); |
| 1905 } | 1914 } |
| 1906 | 1915 |
| 1907 void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext& context) { | 1916 void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext& context) { |
| 1908 NOTREACHED(); | 1917 NOTREACHED(); |
| 1909 } | 1918 } |
| 1910 | 1919 |
| 1911 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( | 1920 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( |
| 1912 float device_scale_factor) { | 1921 float device_scale_factor) { |
| 1922 // TODO(wjmaclean): can host_ ever be null? |
| 1913 if (!host_ || !window_->GetRootWindow()) | 1923 if (!host_ || !window_->GetRootWindow()) |
| 1914 return; | 1924 return; |
| 1915 | 1925 |
| 1916 UpdateScreenInfo(window_); | 1926 UpdateScreenInfo(window_); |
| 1917 | 1927 |
| 1918 device_scale_factor_ = device_scale_factor; | 1928 device_scale_factor_ = device_scale_factor; |
| 1919 const gfx::Display display = gfx::Screen::GetScreen()-> | 1929 const gfx::Display display = gfx::Screen::GetScreen()-> |
| 1920 GetDisplayNearestWindow(window_); | 1930 GetDisplayNearestWindow(window_); |
| 1921 DCHECK_EQ(device_scale_factor, display.device_scale_factor()); | 1931 DCHECK_EQ(device_scale_factor, display.device_scale_factor()); |
| 1922 current_cursor_.SetDisplayInfo(display); | 1932 current_cursor_.SetDisplayInfo(display); |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2479 // RenderWidgetHostViewAura, private: | 2489 // RenderWidgetHostViewAura, private: |
| 2480 | 2490 |
| 2481 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2491 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| 2482 // Ask the RWH to drop reference to us. | 2492 // Ask the RWH to drop reference to us. |
| 2483 if (!is_guest_view_hack_) | 2493 if (!is_guest_view_hack_) |
| 2484 host_->ViewDestroyed(); | 2494 host_->ViewDestroyed(); |
| 2485 | 2495 |
| 2486 selection_controller_.reset(); | 2496 selection_controller_.reset(); |
| 2487 selection_controller_client_.reset(); | 2497 selection_controller_client_.reset(); |
| 2488 | 2498 |
| 2489 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { | |
| 2490 host_->delegate()->GetInputEventRouter()->RemoveSurfaceIdNamespaceOwner( | |
| 2491 GetSurfaceIdNamespace()); | |
| 2492 } | |
| 2493 delegated_frame_host_.reset(); | 2499 delegated_frame_host_.reset(); |
| 2494 window_observer_.reset(); | 2500 window_observer_.reset(); |
| 2495 if (window_) { | 2501 if (window_) { |
| 2496 if (window_->GetHost()) | 2502 if (window_->GetHost()) |
| 2497 window_->GetHost()->RemoveObserver(this); | 2503 window_->GetHost()->RemoveObserver(this); |
| 2498 UnlockMouse(); | 2504 UnlockMouse(); |
| 2499 aura::client::SetTooltipText(window_, NULL); | 2505 aura::client::SetTooltipText(window_, NULL); |
| 2500 gfx::Screen::GetScreen()->RemoveObserver(this); | 2506 gfx::Screen::GetScreen()->RemoveObserver(this); |
| 2501 | 2507 |
| 2502 // This call is usually no-op since |this| object is already removed from | 2508 // This call is usually no-op since |this| object is already removed from |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2620 bool RenderWidgetHostViewAura::NeedsMouseCapture() { | 2626 bool RenderWidgetHostViewAura::NeedsMouseCapture() { |
| 2621 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 2627 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 2622 return NeedsInputGrab(); | 2628 return NeedsInputGrab(); |
| 2623 #endif | 2629 #endif |
| 2624 return false; | 2630 return false; |
| 2625 } | 2631 } |
| 2626 | 2632 |
| 2627 void RenderWidgetHostViewAura::FinishImeCompositionSession() { | 2633 void RenderWidgetHostViewAura::FinishImeCompositionSession() { |
| 2628 if (!has_composition_text_) | 2634 if (!has_composition_text_) |
| 2629 return; | 2635 return; |
| 2636 // TODO(wjmaclean): can host_ ever be null? |
| 2630 if (host_) { | 2637 if (host_) { |
| 2631 host_->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), | 2638 host_->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), |
| 2632 false); | 2639 false); |
| 2633 } | 2640 } |
| 2634 ImeCancelComposition(); | 2641 ImeCancelComposition(); |
| 2635 } | 2642 } |
| 2636 | 2643 |
| 2637 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( | 2644 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( |
| 2638 blink::WebMouseEvent* event) { | 2645 blink::WebMouseEvent* event) { |
| 2639 // If the mouse has just entered, we must report zero movementX/Y. Hence we | 2646 // If the mouse has just entered, we must report zero movementX/Y. Hence we |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3089 | 3096 |
| 3090 //////////////////////////////////////////////////////////////////////////////// | 3097 //////////////////////////////////////////////////////////////////////////////// |
| 3091 // RenderWidgetHostViewBase, public: | 3098 // RenderWidgetHostViewBase, public: |
| 3092 | 3099 |
| 3093 // static | 3100 // static |
| 3094 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 3101 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3095 GetScreenInfoForWindow(results, NULL); | 3102 GetScreenInfoForWindow(results, NULL); |
| 3096 } | 3103 } |
| 3097 | 3104 |
| 3098 } // namespace content | 3105 } // namespace content |
| OLD | NEW |