Chromium Code Reviews| 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 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 aura::Window* root_window = window_->GetRootWindow(); | 1001 aura::Window* root_window = window_->GetRootWindow(); |
| 1002 aura::client::TooltipClient* tooltip_client = | 1002 aura::client::TooltipClient* tooltip_client = |
| 1003 aura::client::GetTooltipClient(root_window); | 1003 aura::client::GetTooltipClient(root_window); |
| 1004 if (tooltip_client) { | 1004 if (tooltip_client) { |
| 1005 tooltip_client->UpdateTooltip(window_); | 1005 tooltip_client->UpdateTooltip(window_); |
| 1006 // Content tooltips should be visible indefinitely. | 1006 // Content tooltips should be visible indefinitely. |
| 1007 tooltip_client->SetTooltipShownTimeout(window_, 0); | 1007 tooltip_client->SetTooltipShownTimeout(window_, 0); |
| 1008 } | 1008 } |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 void RenderWidgetHostViewAura::SelectionChanged(const base::string16& text, | |
| 1012 size_t offset, | |
| 1013 const gfx::Range& range) { | |
| 1014 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | |
| 1015 | |
| 1016 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
| 1017 if (text.empty() || range.is_empty()) | |
| 1018 return; | |
| 1019 size_t pos = range.GetMin() - offset; | |
| 1020 size_t n = range.length(); | |
| 1021 | |
| 1022 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | |
| 1023 if (pos >= text.length()) { | |
| 1024 NOTREACHED() << "The text can not cover range."; | |
| 1025 return; | |
| 1026 } | |
| 1027 | |
| 1028 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | |
| 1029 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | |
| 1030 clipboard_writer.WriteText(text.substr(pos, n)); | |
| 1031 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | |
| 1032 } | |
| 1033 | |
| 1034 gfx::Size RenderWidgetHostViewAura::GetRequestedRendererSize() const { | 1011 gfx::Size RenderWidgetHostViewAura::GetRequestedRendererSize() const { |
| 1035 return delegated_frame_host_->GetRequestedRendererSize(); | 1012 return delegated_frame_host_->GetRequestedRendererSize(); |
| 1036 } | 1013 } |
| 1037 | 1014 |
| 1038 void RenderWidgetHostViewAura::CopyFromCompositingSurface( | 1015 void RenderWidgetHostViewAura::CopyFromCompositingSurface( |
| 1039 const gfx::Rect& src_subrect, | 1016 const gfx::Rect& src_subrect, |
| 1040 const gfx::Size& dst_size, | 1017 const gfx::Size& dst_size, |
| 1041 const ReadbackRequestCallback& callback, | 1018 const ReadbackRequestCallback& callback, |
| 1042 const SkColorType preferred_color_type) { | 1019 const SkColorType preferred_color_type) { |
| 1043 delegated_frame_host_->CopyFromCompositingSurface( | 1020 delegated_frame_host_->CopyFromCompositingSurface( |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 return false; | 1514 return false; |
| 1538 *rect = ConvertRectToScreen(composition_character_bounds->at(index)); | 1515 *rect = ConvertRectToScreen(composition_character_bounds->at(index)); |
| 1539 return true; | 1516 return true; |
| 1540 } | 1517 } |
| 1541 | 1518 |
| 1542 bool RenderWidgetHostViewAura::HasCompositionText() const { | 1519 bool RenderWidgetHostViewAura::HasCompositionText() const { |
| 1543 return has_composition_text_; | 1520 return has_composition_text_; |
| 1544 } | 1521 } |
| 1545 | 1522 |
| 1546 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const { | 1523 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const { |
| 1547 range->set_start(selection_text_offset_); | 1524 if (!text_input_manager_) |
| 1548 range->set_end(selection_text_offset_ + selection_text_.length()); | 1525 return false; |
| 1526 | |
| 1527 const TextInputManager::TextSelection* selection = | |
| 1528 text_input_manager_->GetTextSelection(); | |
| 1529 if (!selection) | |
| 1530 return false; | |
| 1531 | |
| 1532 range->set_start(selection->offset); | |
| 1533 range->set_end(selection->offset + selection->text.length()); | |
| 1549 return true; | 1534 return true; |
| 1550 } | 1535 } |
| 1551 | 1536 |
| 1552 bool RenderWidgetHostViewAura::GetCompositionTextRange( | 1537 bool RenderWidgetHostViewAura::GetCompositionTextRange( |
| 1553 gfx::Range* range) const { | 1538 gfx::Range* range) const { |
| 1554 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. | 1539 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. |
| 1555 NOTIMPLEMENTED(); | 1540 NOTIMPLEMENTED(); |
| 1556 return false; | 1541 return false; |
| 1557 } | 1542 } |
| 1558 | 1543 |
| 1559 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range* range) const { | 1544 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range* range) const { |
| 1560 range->set_start(selection_range_.start()); | 1545 if (!text_input_manager_) |
| 1561 range->set_end(selection_range_.end()); | 1546 return false; |
| 1547 | |
| 1548 const TextInputManager::TextSelection* selection = | |
| 1549 text_input_manager_->GetTextSelection(); | |
| 1550 if (!selection) | |
| 1551 return false; | |
| 1552 | |
| 1553 range->set_start(selection->range.start()); | |
| 1554 range->set_end(selection->range.end()); | |
| 1562 return true; | 1555 return true; |
| 1563 } | 1556 } |
| 1564 | 1557 |
| 1565 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range& range) { | 1558 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range& range) { |
| 1566 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. | 1559 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. |
| 1567 NOTIMPLEMENTED(); | 1560 NOTIMPLEMENTED(); |
| 1568 return false; | 1561 return false; |
| 1569 } | 1562 } |
| 1570 | 1563 |
| 1571 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range& range) { | 1564 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range& range) { |
| 1572 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. | 1565 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. |
| 1573 NOTIMPLEMENTED(); | 1566 NOTIMPLEMENTED(); |
| 1574 return false; | 1567 return false; |
| 1575 } | 1568 } |
| 1576 | 1569 |
| 1577 bool RenderWidgetHostViewAura::GetTextFromRange( | 1570 bool RenderWidgetHostViewAura::GetTextFromRange( |
| 1578 const gfx::Range& range, | 1571 const gfx::Range& range, |
| 1579 base::string16* text) const { | 1572 base::string16* text) const { |
| 1580 gfx::Range selection_text_range(selection_text_offset_, | 1573 if (!text_input_manager_) |
| 1581 selection_text_offset_ + selection_text_.length()); | 1574 return false; |
| 1575 | |
| 1576 const TextInputManager::TextSelection* selection = | |
| 1577 text_input_manager_->GetTextSelection(); | |
| 1578 if (!selection) | |
| 1579 return false; | |
| 1580 | |
| 1581 gfx::Range selection_text_range(selection->offset, | |
| 1582 selection->offset + selection->text.length()); | |
| 1582 | 1583 |
| 1583 if (!selection_text_range.Contains(range)) { | 1584 if (!selection_text_range.Contains(range)) { |
| 1584 text->clear(); | 1585 text->clear(); |
| 1585 return false; | 1586 return false; |
| 1586 } | 1587 } |
| 1587 if (selection_text_range.EqualsIgnoringDirection(range)) { | 1588 if (selection_text_range.EqualsIgnoringDirection(range)) { |
| 1588 // Avoid calling substr whose performance is low. | 1589 // Avoid calling substr whose performance is low. |
| 1589 *text = selection_text_; | 1590 *text = selection->text; |
| 1590 } else { | 1591 } else { |
| 1591 *text = selection_text_.substr( | 1592 *text = selection->text.substr(range.GetMin() - selection->offset, |
| 1592 range.GetMin() - selection_text_offset_, | 1593 range.length()); |
| 1593 range.length()); | |
| 1594 } | 1594 } |
| 1595 return true; | 1595 return true; |
| 1596 } | 1596 } |
| 1597 | 1597 |
| 1598 void RenderWidgetHostViewAura::OnInputMethodChanged() { | 1598 void RenderWidgetHostViewAura::OnInputMethodChanged() { |
| 1599 // TODO(wjmaclean): can host_ ever be null? | 1599 // TODO(wjmaclean): can host_ ever be null? |
| 1600 if (!host_) | 1600 if (!host_) |
| 1601 return; | 1601 return; |
| 1602 | 1602 |
| 1603 // TODO(suzhe): implement the newly added “locale” property of HTML DOM | 1603 // TODO(suzhe): implement the newly added “locale” property of HTML DOM |
| (...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2992 has_composition_text_ = false; | 2992 has_composition_text_ = false; |
| 2993 } | 2993 } |
| 2994 | 2994 |
| 2995 void RenderWidgetHostViewAura::OnSelectionBoundsChanged( | 2995 void RenderWidgetHostViewAura::OnSelectionBoundsChanged( |
| 2996 TextInputManager* text_input_manager, | 2996 TextInputManager* text_input_manager, |
| 2997 RenderWidgetHostViewBase* updated_view) { | 2997 RenderWidgetHostViewBase* updated_view) { |
| 2998 if (GetInputMethod()) | 2998 if (GetInputMethod()) |
| 2999 GetInputMethod()->OnCaretBoundsChanged(this); | 2999 GetInputMethod()->OnCaretBoundsChanged(this); |
| 3000 } | 3000 } |
| 3001 | 3001 |
| 3002 void RenderWidgetHostViewAura::OnTextSelectionChanged( | |
| 3003 TextInputManager* text_input_manager, | |
| 3004 RenderWidgetHostViewBase* updated_view) { | |
| 3005 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
|
EhsanK
2016/07/18 15:21:29
This part could live in TextInputManager. But I th
| |
| 3006 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) | |
| 3007 return; | |
| 3008 | |
| 3009 const TextInputManager::TextSelection* text_selection = | |
| 3010 GetTextInputManager()->GetTextSelection(); | |
| 3011 | |
| 3012 if (text_selection->text.empty() || text_selection->range.is_empty()) | |
| 3013 return; | |
| 3014 size_t pos = text_selection->range.GetMin() - text_selection->offset; | |
| 3015 size_t n = text_selection->range.length(); | |
| 3016 | |
| 3017 DCHECK(pos + n <= text_selection->text.length()) | |
| 3018 << "The text can not fully cover range."; | |
| 3019 if (pos >= text_selection->text.length()) { | |
| 3020 NOTREACHED() << "The text can not cover range."; | |
| 3021 return; | |
| 3022 } | |
| 3023 | |
| 3024 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | |
| 3025 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | |
| 3026 clipboard_writer.WriteText(text_selection->text.substr(pos, n)); | |
| 3027 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | |
| 3028 } | |
| 3029 | |
| 3002 //////////////////////////////////////////////////////////////////////////////// | 3030 //////////////////////////////////////////////////////////////////////////////// |
| 3003 // RenderWidgetHostViewBase, public: | 3031 // RenderWidgetHostViewBase, public: |
| 3004 | 3032 |
| 3005 // static | 3033 // static |
| 3006 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 3034 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3007 GetScreenInfoForWindow(results, NULL); | 3035 GetScreenInfoForWindow(results, NULL); |
| 3008 } | 3036 } |
| 3009 | 3037 |
| 3010 } // namespace content | 3038 } // namespace content |
| OLD | NEW |