Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 2208093004: Use focused RenderWidgetHostImpl instead of TextInputManager::GetActiveWidget() to obtain TextSelec… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed some crashes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 } 1528 }
1529 1529
1530 bool RenderWidgetHostViewAura::HasCompositionText() const { 1530 bool RenderWidgetHostViewAura::HasCompositionText() const {
1531 return has_composition_text_; 1531 return has_composition_text_;
1532 } 1532 }
1533 1533
1534 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const { 1534 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const {
1535 if (!text_input_manager_) 1535 if (!text_input_manager_)
1536 return false; 1536 return false;
1537 1537
1538 const TextInputManager::TextSelection* selection = 1538 RenderWidgetHostViewBase* view = nullptr;
Charlie Reis 2016/08/04 19:56:50 nit: Wrong indent. Also, this block needs a comme
EhsanK 2016/08/04 22:29:55 Acknowledged.
1539 text_input_manager_->GetTextSelection(); 1539 if (is_guest_view_hack_)
Charlie Reis 2016/08/04 19:56:50 Wow. I can't wait till we switch from BrowserPlugi
EhsanK 2016/08/04 22:29:54 Me too. Although this could take a while since Mim
1540 if (!selection) 1540 view = const_cast<RenderWidgetHostViewAura*>(this);
Charlie Reis 2016/08/04 19:56:50 Using const_cast here doesn't seem ok.
EhsanK 2016/08/04 22:29:55 This is similar to the issue we had with RWHV::Get
1541 else {
Charlie Reis 2016/08/04 19:56:50 Style nit: If the else branch needs braces, so doe
EhsanK 2016/08/04 22:29:54 Acknowledged.
1542 RenderWidgetHostImpl* host = ActiveOrFocusedWidget();
1543 if (host)
1544 view = host->GetView();
1545 }
1546 if (!view)
1541 return false; 1547 return false;
1542 1548
1549 const TextInputManager::TextSelection* selection =
1550 text_input_manager_->GetTextSelection(view);
1543 range->set_start(selection->offset); 1551 range->set_start(selection->offset);
1544 range->set_end(selection->offset + selection->text.length()); 1552 range->set_end(selection->offset + selection->text.length());
1545 return true; 1553 return true;
1546 } 1554 }
1547 1555
1548 bool RenderWidgetHostViewAura::GetCompositionTextRange( 1556 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1549 gfx::Range* range) const { 1557 gfx::Range* range) const {
1550 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. 1558 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1551 NOTIMPLEMENTED(); 1559 NOTIMPLEMENTED();
1552 return false; 1560 return false;
1553 } 1561 }
1554 1562
1555 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range* range) const { 1563 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range* range) const {
1556 if (!text_input_manager_) 1564 if (!text_input_manager_)
1557 return false; 1565 return false;
1558 1566
1559 const TextInputManager::TextSelection* selection = 1567 RenderWidgetHostViewBase* view = nullptr;
1560 text_input_manager_->GetTextSelection(); 1568 if (is_guest_view_hack_)
1561 if (!selection) 1569 view = const_cast<RenderWidgetHostViewAura*>(this);
1570 else {
1571 RenderWidgetHostImpl* host = ActiveOrFocusedWidget();
1572 if (host)
1573 view = host->GetView();
1574 }
1575 if (!view)
1562 return false; 1576 return false;
1563 1577
1578 const TextInputManager::TextSelection* selection =
1579 text_input_manager_->GetTextSelection(view);
1564 range->set_start(selection->range.start()); 1580 range->set_start(selection->range.start());
1565 range->set_end(selection->range.end()); 1581 range->set_end(selection->range.end());
1566 return true; 1582 return true;
1567 } 1583 }
1568 1584
1569 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range& range) { 1585 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range& range) {
1570 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. 1586 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1571 NOTIMPLEMENTED(); 1587 NOTIMPLEMENTED();
1572 return false; 1588 return false;
1573 } 1589 }
1574 1590
1575 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range& range) { 1591 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range& range) {
1576 // TODO(suzhe): implement this method when fixing http://crbug.com/55130. 1592 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1577 NOTIMPLEMENTED(); 1593 NOTIMPLEMENTED();
1578 return false; 1594 return false;
1579 } 1595 }
1580 1596
1581 bool RenderWidgetHostViewAura::GetTextFromRange( 1597 bool RenderWidgetHostViewAura::GetTextFromRange(
1582 const gfx::Range& range, 1598 const gfx::Range& range,
1583 base::string16* text) const { 1599 base::string16* text) const {
1584 if (!text_input_manager_) 1600 if (!text_input_manager_)
1585 return false; 1601 return false;
1586 1602
1587 const TextInputManager::TextSelection* selection = 1603 RenderWidgetHostViewBase* view = nullptr;
Charlie Reis 2016/08/04 19:56:50 We shouldn't be copy/pasting this pattern.
EhsanK 2016/08/04 22:29:54 Now I am using (something similar) this pattern on
1588 text_input_manager_->GetTextSelection(); 1604 if (is_guest_view_hack_)
1589 if (!selection) 1605 view = const_cast<RenderWidgetHostViewAura*>(this);
1606 else {
1607 RenderWidgetHostImpl* host = ActiveOrFocusedWidget();
1608 if (host)
1609 view = host->GetView();
1610 }
1611 if (!view)
1590 return false; 1612 return false;
1591 1613
1614 const TextInputManager::TextSelection* selection =
1615 text_input_manager_->GetTextSelection(view);
1592 gfx::Range selection_text_range(selection->offset, 1616 gfx::Range selection_text_range(selection->offset,
1593 selection->offset + selection->text.length()); 1617 selection->offset + selection->text.length());
1594 1618
1595 if (!selection_text_range.Contains(range)) { 1619 if (!selection_text_range.Contains(range)) {
1596 text->clear(); 1620 text->clear();
1597 return false; 1621 return false;
1598 } 1622 }
1599 if (selection_text_range.EqualsIgnoringDirection(range)) { 1623 if (selection_text_range.EqualsIgnoringDirection(range)) {
1600 // Avoid calling substr whose performance is low. 1624 // Avoid calling substr whose performance is low.
1601 *text = selection->text; 1625 *text = selection->text;
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 TextInputManager* text_input_manager, 3055 TextInputManager* text_input_manager,
3032 RenderWidgetHostViewBase* updated_view) { 3056 RenderWidgetHostViewBase* updated_view) {
3033 if (GetInputMethod()) 3057 if (GetInputMethod())
3034 GetInputMethod()->OnCaretBoundsChanged(this); 3058 GetInputMethod()->OnCaretBoundsChanged(this);
3035 } 3059 }
3036 3060
3037 void RenderWidgetHostViewAura::OnTextSelectionChanged( 3061 void RenderWidgetHostViewAura::OnTextSelectionChanged(
3038 TextInputManager* text_input_manager, 3062 TextInputManager* text_input_manager,
3039 RenderWidgetHostViewBase* updated_view) { 3063 RenderWidgetHostViewBase* updated_view) {
3040 #if defined(USE_X11) && !defined(OS_CHROMEOS) 3064 #if defined(USE_X11) && !defined(OS_CHROMEOS)
3041 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) 3065 if (!text_input_manager_)
3042 return; 3066 return;
3043 3067
3044 const TextInputManager::TextSelection* text_selection = 3068 RenderWidgetHostViewBase* view = nullptr;
3045 GetTextInputManager()->GetTextSelection(); 3069 if (is_guest_view_hack_)
3070 view = this;
3071 else {
3072 RenderWidgetHostImpl* host = ActiveOrFocusedWidget();
3073 if (host)
3074 view = host->GetView();
3075 }
3076 if (!view)
3077 return;
3046 3078
3047 if (text_selection->text.empty() || text_selection->range.is_empty()) 3079 const TextInputManager::TextSelection* selection =
3080 text_input_manager_->GetTextSelection(view);
3081
3082 if (selection->text.empty() || selection->range.is_empty())
3048 return; 3083 return;
3049 size_t pos = text_selection->range.GetMin() - text_selection->offset; 3084 size_t pos = selection->range.GetMin() - selection->offset;
3050 size_t n = text_selection->range.length(); 3085 size_t n = selection->range.length();
3051 3086
3052 DCHECK(pos + n <= text_selection->text.length()) 3087 DCHECK(pos + n <= selection->text.length())
3053 << "The text can not fully cover range."; 3088 << "The text can not fully cover range.";
3054 if (pos >= text_selection->text.length()) { 3089 if (pos >= selection->text.length()) {
3055 NOTREACHED() << "The text can not cover range."; 3090 NOTREACHED() << "The text can not cover range.";
3056 return; 3091 return;
3057 } 3092 }
3058 3093
3059 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. 3094 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3060 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); 3095 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3061 clipboard_writer.WriteText(text_selection->text.substr(pos, n)); 3096 clipboard_writer.WriteText(selection->text.substr(pos, n));
3062 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) 3097 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
3063 } 3098 }
3064 3099
3065 //////////////////////////////////////////////////////////////////////////////// 3100 ////////////////////////////////////////////////////////////////////////////////
3066 // RenderWidgetHostViewBase, public: 3101 // RenderWidgetHostViewBase, public:
3067 3102
3068 // static 3103 // static
3069 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 3104 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
3070 GetScreenInfoForWindow(results, NULL); 3105 GetScreenInfoForWindow(results, NULL);
3071 } 3106 }
3072 3107
3073 } // namespace content 3108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698