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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 return; | 1607 return; |
1608 ImeEventGuard guard(this); | 1608 ImeEventGuard guard(this); |
1609 if (!webwidget_->setComposition( | 1609 if (!webwidget_->setComposition( |
1610 text, WebVector<WebCompositionUnderline>(underlines), | 1610 text, WebVector<WebCompositionUnderline>(underlines), |
1611 selection_start, selection_end)) { | 1611 selection_start, selection_end)) { |
1612 // If we failed to set the composition text, then we need to let the browser | 1612 // If we failed to set the composition text, then we need to let the browser |
1613 // process to cancel the input method's ongoing composition session, to make | 1613 // process to cancel the input method's ongoing composition session, to make |
1614 // sure we are in a consistent state. | 1614 // sure we are in a consistent state. |
1615 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1615 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1616 } | 1616 } |
1617 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1618 UpdateCompositionInfo(true); | 1617 UpdateCompositionInfo(true); |
1619 #endif | |
1620 } | 1618 } |
1621 | 1619 |
1622 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1620 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
1623 const gfx::Range& replacement_range, | 1621 const gfx::Range& replacement_range, |
1624 bool keep_selection) { | 1622 bool keep_selection) { |
1625 if (!ShouldHandleImeEvent()) | 1623 if (!ShouldHandleImeEvent()) |
1626 return; | 1624 return; |
1627 ImeEventGuard guard(this); | 1625 ImeEventGuard guard(this); |
1628 handling_input_event_ = true; | 1626 handling_input_event_ = true; |
1629 if (text.length()) | 1627 if (text.length()) |
1630 webwidget_->confirmComposition(text); | 1628 webwidget_->confirmComposition(text); |
1631 else if (keep_selection) | 1629 else if (keep_selection) |
1632 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1630 webwidget_->confirmComposition(WebWidget::KeepSelection); |
1633 else | 1631 else |
1634 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1632 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
1635 handling_input_event_ = false; | 1633 handling_input_event_ = false; |
1636 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1637 UpdateCompositionInfo(true); | 1634 UpdateCompositionInfo(true); |
1638 #endif | |
1639 } | 1635 } |
1640 | 1636 |
1641 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { | 1637 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { |
1642 // During shutdown we can just ignore this message. | 1638 // During shutdown we can just ignore this message. |
1643 if (!webwidget_) | 1639 if (!webwidget_) |
1644 return; | 1640 return; |
1645 | 1641 |
1646 // Even if the browser provides an empty damage rect, it's still expecting to | 1642 // Even if the browser provides an empty damage rect, it's still expecting to |
1647 // receive a repaint ack so just damage the entire widget bounds. | 1643 // receive a repaint ack so just damage the entire widget bounds. |
1648 if (size_to_paint.IsEmpty()) { | 1644 if (size_to_paint.IsEmpty()) { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 if (selection_anchor_rect_ != params.anchor_rect || | 1954 if (selection_anchor_rect_ != params.anchor_rect || |
1959 selection_focus_rect_ != params.focus_rect) { | 1955 selection_focus_rect_ != params.focus_rect) { |
1960 selection_anchor_rect_ = params.anchor_rect; | 1956 selection_anchor_rect_ = params.anchor_rect; |
1961 selection_focus_rect_ = params.focus_rect; | 1957 selection_focus_rect_ = params.focus_rect; |
1962 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); | 1958 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
1963 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); | 1959 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
1964 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 1960 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
1965 } | 1961 } |
1966 } | 1962 } |
1967 | 1963 |
1968 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1969 UpdateCompositionInfo(false); | 1964 UpdateCompositionInfo(false); |
1970 #endif | |
1971 } | 1965 } |
1972 | 1966 |
1973 // Check blink::WebTextInputType and ui::TextInputType is kept in sync. | 1967 // Check blink::WebTextInputType and ui::TextInputType is kept in sync. |
1974 COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \ | 1968 COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \ |
1975 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); | 1969 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); |
1976 COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \ | 1970 COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \ |
1977 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); | 1971 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); |
1978 COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \ | 1972 COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \ |
1979 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums); | 1973 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums); |
1980 COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \ | 1974 COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 "blink::WebTextInputType and ui::TextInputType not synchronized"; | 2007 "blink::WebTextInputType and ui::TextInputType not synchronized"; |
2014 return static_cast<ui::TextInputType>(type); | 2008 return static_cast<ui::TextInputType>(type); |
2015 } | 2009 } |
2016 | 2010 |
2017 ui::TextInputType RenderWidget::GetTextInputType() { | 2011 ui::TextInputType RenderWidget::GetTextInputType() { |
2018 if (webwidget_) | 2012 if (webwidget_) |
2019 return WebKitToUiTextInputType(webwidget_->textInputInfo().type); | 2013 return WebKitToUiTextInputType(webwidget_->textInputInfo().type); |
2020 return ui::TEXT_INPUT_TYPE_NONE; | 2014 return ui::TEXT_INPUT_TYPE_NONE; |
2021 } | 2015 } |
2022 | 2016 |
2023 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
2024 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 2017 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
2025 #if defined(OS_ANDROID) | 2018 #if defined(OS_ANDROID) |
2026 // Sending composition info makes sense only in Lollipop (API level 21) | 2019 // Sending composition info makes sense only in Lollipop (API level 21) |
2027 // and above due to the API availability. | 2020 // and above due to the API availability. |
2028 if (base::android::BuildInfo::GetInstance()->sdk_int() < 21) | 2021 if (base::android::BuildInfo::GetInstance()->sdk_int() < 21) |
2029 return; | 2022 return; |
2030 #endif | 2023 #endif |
2031 | 2024 |
2032 gfx::Range range = gfx::Range(); | 2025 gfx::Range range = gfx::Range(); |
2033 if (should_update_range) { | 2026 if (should_update_range) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 if (composition_range_ != range) | 2064 if (composition_range_ != range) |
2072 return true; | 2065 return true; |
2073 if (bounds.size() != composition_character_bounds_.size()) | 2066 if (bounds.size() != composition_character_bounds_.size()) |
2074 return true; | 2067 return true; |
2075 for (size_t i = 0; i < bounds.size(); ++i) { | 2068 for (size_t i = 0; i < bounds.size(); ++i) { |
2076 if (bounds[i] != composition_character_bounds_[i]) | 2069 if (bounds[i] != composition_character_bounds_[i]) |
2077 return true; | 2070 return true; |
2078 } | 2071 } |
2079 return false; | 2072 return false; |
2080 } | 2073 } |
2081 #endif | |
2082 | 2074 |
2083 #if defined(OS_ANDROID) | 2075 #if defined(OS_ANDROID) |
2084 void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) { | 2076 void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) { |
2085 // If not initialized, default to white. Note that 0 is different from black | 2077 // If not initialized, default to white. Note that 0 is different from black |
2086 // as black still has alpha 0xFF. | 2078 // as black still has alpha 0xFF. |
2087 if (!bg_color) | 2079 if (!bg_color) |
2088 bg_color = SK_ColorWHITE; | 2080 bg_color = SK_ColorWHITE; |
2089 | 2081 |
2090 if (bg_color != body_background_color_) { | 2082 if (bg_color != body_background_color_) { |
2091 body_background_color_ = bg_color; | 2083 body_background_color_ = bg_color; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2126 ImeEventGuard guard(this); | 2118 ImeEventGuard guard(this); |
2127 // If the last text input type is not None, then we should finish any | 2119 // If the last text input type is not None, then we should finish any |
2128 // ongoing composition regardless of the new text input type. | 2120 // ongoing composition regardless of the new text input type. |
2129 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 2121 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
2130 // If a composition text exists, then we need to let the browser process | 2122 // If a composition text exists, then we need to let the browser process |
2131 // to cancel the input method's ongoing composition session. | 2123 // to cancel the input method's ongoing composition session. |
2132 if (webwidget_->confirmComposition()) | 2124 if (webwidget_->confirmComposition()) |
2133 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 2125 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
2134 } | 2126 } |
2135 | 2127 |
2136 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
2137 UpdateCompositionInfo(true); | 2128 UpdateCompositionInfo(true); |
2138 #endif | |
2139 } | 2129 } |
2140 | 2130 |
2141 void RenderWidget::didHandleGestureEvent( | 2131 void RenderWidget::didHandleGestureEvent( |
2142 const WebGestureEvent& event, | 2132 const WebGestureEvent& event, |
2143 bool event_cancelled) { | 2133 bool event_cancelled) { |
2144 #if defined(OS_ANDROID) || defined(USE_AURA) | 2134 #if defined(OS_ANDROID) || defined(USE_AURA) |
2145 if (event_cancelled) | 2135 if (event_cancelled) |
2146 return; | 2136 return; |
2147 if (event.type == WebInputEvent::GestureTap) { | 2137 if (event.type == WebInputEvent::GestureTap) { |
2148 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 2138 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2328 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2339 video_hole_frames_.AddObserver(frame); | 2329 video_hole_frames_.AddObserver(frame); |
2340 } | 2330 } |
2341 | 2331 |
2342 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2332 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2343 video_hole_frames_.RemoveObserver(frame); | 2333 video_hole_frames_.RemoveObserver(frame); |
2344 } | 2334 } |
2345 #endif // defined(VIDEO_HOLE) | 2335 #endif // defined(VIDEO_HOLE) |
2346 | 2336 |
2347 } // namespace content | 2337 } // namespace content |
OLD | NEW |