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 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 return; | 1562 return; |
1563 ImeEventGuard guard(this); | 1563 ImeEventGuard guard(this); |
1564 if (!webwidget_->setComposition( | 1564 if (!webwidget_->setComposition( |
1565 text, WebVector<WebCompositionUnderline>(underlines), | 1565 text, WebVector<WebCompositionUnderline>(underlines), |
1566 selection_start, selection_end)) { | 1566 selection_start, selection_end)) { |
1567 // If we failed to set the composition text, then we need to let the browser | 1567 // If we failed to set the composition text, then we need to let the browser |
1568 // process to cancel the input method's ongoing composition session, to make | 1568 // process to cancel the input method's ongoing composition session, to make |
1569 // sure we are in a consistent state. | 1569 // sure we are in a consistent state. |
1570 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1570 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1571 } | 1571 } |
1572 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1573 UpdateCompositionInfo(true); | 1572 UpdateCompositionInfo(true); |
1574 #endif | |
1575 } | 1573 } |
1576 | 1574 |
1577 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1575 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
1578 const gfx::Range& replacement_range, | 1576 const gfx::Range& replacement_range, |
1579 bool keep_selection) { | 1577 bool keep_selection) { |
1580 if (!ShouldHandleImeEvent()) | 1578 if (!ShouldHandleImeEvent()) |
1581 return; | 1579 return; |
1582 ImeEventGuard guard(this); | 1580 ImeEventGuard guard(this); |
1583 handling_input_event_ = true; | 1581 handling_input_event_ = true; |
1584 if (text.length()) | 1582 if (text.length()) |
1585 webwidget_->confirmComposition(text); | 1583 webwidget_->confirmComposition(text); |
1586 else if (keep_selection) | 1584 else if (keep_selection) |
1587 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1585 webwidget_->confirmComposition(WebWidget::KeepSelection); |
1588 else | 1586 else |
1589 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1587 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
1590 handling_input_event_ = false; | 1588 handling_input_event_ = false; |
1591 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1592 UpdateCompositionInfo(true); | 1589 UpdateCompositionInfo(true); |
1593 #endif | |
1594 } | 1590 } |
1595 | 1591 |
1596 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { | 1592 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { |
1597 // During shutdown we can just ignore this message. | 1593 // During shutdown we can just ignore this message. |
1598 if (!webwidget_) | 1594 if (!webwidget_) |
1599 return; | 1595 return; |
1600 | 1596 |
1601 // Even if the browser provides an empty damage rect, it's still expecting to | 1597 // Even if the browser provides an empty damage rect, it's still expecting to |
1602 // receive a repaint ack so just damage the entire widget bounds. | 1598 // receive a repaint ack so just damage the entire widget bounds. |
1603 if (size_to_paint.IsEmpty()) { | 1599 if (size_to_paint.IsEmpty()) { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 if (selection_anchor_rect_ != params.anchor_rect || | 1909 if (selection_anchor_rect_ != params.anchor_rect || |
1914 selection_focus_rect_ != params.focus_rect) { | 1910 selection_focus_rect_ != params.focus_rect) { |
1915 selection_anchor_rect_ = params.anchor_rect; | 1911 selection_anchor_rect_ = params.anchor_rect; |
1916 selection_focus_rect_ = params.focus_rect; | 1912 selection_focus_rect_ = params.focus_rect; |
1917 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); | 1913 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
1918 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); | 1914 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
1919 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 1915 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
1920 } | 1916 } |
1921 } | 1917 } |
1922 | 1918 |
1923 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1924 UpdateCompositionInfo(false); | 1919 UpdateCompositionInfo(false); |
1925 #endif | |
1926 } | 1920 } |
1927 | 1921 |
1928 // Check blink::WebTextInputType and ui::TextInputType is kept in sync. | 1922 // Check blink::WebTextInputType and ui::TextInputType is kept in sync. |
1929 COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \ | 1923 COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \ |
1930 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); | 1924 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); |
1931 COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \ | 1925 COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \ |
1932 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); | 1926 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); |
1933 COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \ | 1927 COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \ |
1934 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums); | 1928 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums); |
1935 COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \ | 1929 COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1968 "blink::WebTextInputType and ui::TextInputType not synchronized"; | 1962 "blink::WebTextInputType and ui::TextInputType not synchronized"; |
1969 return static_cast<ui::TextInputType>(type); | 1963 return static_cast<ui::TextInputType>(type); |
1970 } | 1964 } |
1971 | 1965 |
1972 ui::TextInputType RenderWidget::GetTextInputType() { | 1966 ui::TextInputType RenderWidget::GetTextInputType() { |
1973 if (webwidget_) | 1967 if (webwidget_) |
1974 return WebKitToUiTextInputType(webwidget_->textInputInfo().type); | 1968 return WebKitToUiTextInputType(webwidget_->textInputInfo().type); |
1975 return ui::TEXT_INPUT_TYPE_NONE; | 1969 return ui::TEXT_INPUT_TYPE_NONE; |
1976 } | 1970 } |
1977 | 1971 |
1978 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
1979 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1972 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
1980 #if defined(OS_ANDROID) | 1973 #if defined(OS_ANDROID) |
1981 // Sending composition info makes sense only in Lollipop (API level 21) | 1974 // Sending composition info makes sense only in Lollipop (API level 21) |
1982 // and above due to the API availability. | 1975 // and above due to the API availability. |
1983 if (base::android::BuildInfo::GetInstance()->sdk_int() < 21) | 1976 if (base::android::BuildInfo::GetInstance()->sdk_int() < 21) |
1984 return; | 1977 return; |
1985 #endif | 1978 #endif |
1986 | 1979 |
1987 gfx::Range range = gfx::Range(); | 1980 gfx::Range range = gfx::Range(); |
1988 if (should_update_range) { | 1981 if (should_update_range) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 if (composition_range_ != range) | 2019 if (composition_range_ != range) |
2027 return true; | 2020 return true; |
2028 if (bounds.size() != composition_character_bounds_.size()) | 2021 if (bounds.size() != composition_character_bounds_.size()) |
2029 return true; | 2022 return true; |
2030 for (size_t i = 0; i < bounds.size(); ++i) { | 2023 for (size_t i = 0; i < bounds.size(); ++i) { |
2031 if (bounds[i] != composition_character_bounds_[i]) | 2024 if (bounds[i] != composition_character_bounds_[i]) |
2032 return true; | 2025 return true; |
2033 } | 2026 } |
2034 return false; | 2027 return false; |
2035 } | 2028 } |
2036 #endif | |
2037 | 2029 |
2038 #if defined(OS_ANDROID) | 2030 #if defined(OS_ANDROID) |
2039 void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) { | 2031 void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) { |
2040 // If not initialized, default to white. Note that 0 is different from black | 2032 // If not initialized, default to white. Note that 0 is different from black |
2041 // as black still has alpha 0xFF. | 2033 // as black still has alpha 0xFF. |
2042 if (!bg_color) | 2034 if (!bg_color) |
2043 bg_color = SK_ColorWHITE; | 2035 bg_color = SK_ColorWHITE; |
2044 | 2036 |
2045 if (bg_color != body_background_color_) { | 2037 if (bg_color != body_background_color_) { |
2046 body_background_color_ = bg_color; | 2038 body_background_color_ = bg_color; |
(...skipping 21 matching lines...) Expand all Loading... |
2068 ImeEventGuard guard(this); | 2060 ImeEventGuard guard(this); |
2069 // If the last text input type is not None, then we should finish any | 2061 // If the last text input type is not None, then we should finish any |
2070 // ongoing composition regardless of the new text input type. | 2062 // ongoing composition regardless of the new text input type. |
2071 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 2063 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
2072 // If a composition text exists, then we need to let the browser process | 2064 // If a composition text exists, then we need to let the browser process |
2073 // to cancel the input method's ongoing composition session. | 2065 // to cancel the input method's ongoing composition session. |
2074 if (webwidget_->confirmComposition()) | 2066 if (webwidget_->confirmComposition()) |
2075 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 2067 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
2076 } | 2068 } |
2077 | 2069 |
2078 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID) | |
2079 UpdateCompositionInfo(true); | 2070 UpdateCompositionInfo(true); |
2080 #endif | |
2081 } | 2071 } |
2082 | 2072 |
2083 void RenderWidget::didHandleGestureEvent( | 2073 void RenderWidget::didHandleGestureEvent( |
2084 const WebGestureEvent& event, | 2074 const WebGestureEvent& event, |
2085 bool event_cancelled) { | 2075 bool event_cancelled) { |
2086 #if defined(OS_ANDROID) || defined(USE_AURA) | 2076 #if defined(OS_ANDROID) || defined(USE_AURA) |
2087 if (event_cancelled) | 2077 if (event_cancelled) |
2088 return; | 2078 return; |
2089 if (event.type == WebInputEvent::GestureTap) { | 2079 if (event.type == WebInputEvent::GestureTap) { |
2090 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 2080 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2270 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2281 video_hole_frames_.AddObserver(frame); | 2271 video_hole_frames_.AddObserver(frame); |
2282 } | 2272 } |
2283 | 2273 |
2284 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2274 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2285 video_hole_frames_.RemoveObserver(frame); | 2275 video_hole_frames_.RemoveObserver(frame); |
2286 } | 2276 } |
2287 #endif // defined(VIDEO_HOLE) | 2277 #endif // defined(VIDEO_HOLE) |
2288 | 2278 |
2289 } // namespace content | 2279 } // namespace content |
OLD | NEW |