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