| 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_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 #endif | 924 #endif |
| 925 } | 925 } |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 | 928 |
| 929 void RenderWidgetHostViewMac::ImeCancelComposition() { | 929 void RenderWidgetHostViewMac::ImeCancelComposition() { |
| 930 [cocoa_view_ cancelComposition]; | 930 [cocoa_view_ cancelComposition]; |
| 931 } | 931 } |
| 932 | 932 |
| 933 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( | 933 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( |
| 934 const ui::Range& range, | 934 const gfx::Range& range, |
| 935 const std::vector<gfx::Rect>& character_bounds) { | 935 const std::vector<gfx::Rect>& character_bounds) { |
| 936 // The RangeChanged message is only sent with valid values. The current | 936 // The RangeChanged message is only sent with valid values. The current |
| 937 // caret position (start == end) will be sent if there is no IME range. | 937 // caret position (start == end) will be sent if there is no IME range. |
| 938 [cocoa_view_ setMarkedRange:range.ToNSRange()]; | 938 [cocoa_view_ setMarkedRange:range.ToNSRange()]; |
| 939 composition_range_ = range; | 939 composition_range_ = range; |
| 940 composition_bounds_ = character_bounds; | 940 composition_bounds_ = character_bounds; |
| 941 } | 941 } |
| 942 | 942 |
| 943 void RenderWidgetHostViewMac::DidUpdateBackingStore( | 943 void RenderWidgetHostViewMac::DidUpdateBackingStore( |
| 944 const gfx::Rect& scroll_rect, | 944 const gfx::Rect& scroll_rect, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1068 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
| 1069 [NSApp stopSpeaking:cocoa_view_]; | 1069 [NSApp stopSpeaking:cocoa_view_]; |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 // | 1072 // |
| 1073 // RenderWidgetHostViewCocoa uses the stored selection text, | 1073 // RenderWidgetHostViewCocoa uses the stored selection text, |
| 1074 // which implements NSServicesRequests protocol. | 1074 // which implements NSServicesRequests protocol. |
| 1075 // | 1075 // |
| 1076 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, | 1076 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, |
| 1077 size_t offset, | 1077 size_t offset, |
| 1078 const ui::Range& range) { | 1078 const gfx::Range& range) { |
| 1079 if (range.is_empty() || text.empty()) { | 1079 if (range.is_empty() || text.empty()) { |
| 1080 selected_text_.clear(); | 1080 selected_text_.clear(); |
| 1081 } else { | 1081 } else { |
| 1082 size_t pos = range.GetMin() - offset; | 1082 size_t pos = range.GetMin() - offset; |
| 1083 size_t n = range.length(); | 1083 size_t n = range.length(); |
| 1084 | 1084 |
| 1085 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | 1085 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; |
| 1086 if (pos >= text.length()) { | 1086 if (pos >= text.length()) { |
| 1087 DCHECK(false) << "The text can not cover range."; | 1087 DCHECK(false) << "The text can not cover range."; |
| 1088 return; | 1088 return; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 // Pass reasonable default values if unable to get the actual ones | 1479 // Pass reasonable default values if unable to get the actual ones |
| 1480 // (e.g. CVDisplayLink failed to return them because the display is | 1480 // (e.g. CVDisplayLink failed to return them because the display is |
| 1481 // in sleep mode). | 1481 // in sleep mode). |
| 1482 static const int64 kOneOverSixtyMicroseconds = 16669; | 1482 static const int64 kOneOverSixtyMicroseconds = 16669; |
| 1483 *timebase = base::TimeTicks::Now(), | 1483 *timebase = base::TimeTicks::Now(), |
| 1484 *interval = base::TimeDelta::FromMicroseconds(kOneOverSixtyMicroseconds); | 1484 *interval = base::TimeDelta::FromMicroseconds(kOneOverSixtyMicroseconds); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 bool RenderWidgetHostViewMac::GetLineBreakIndex( | 1487 bool RenderWidgetHostViewMac::GetLineBreakIndex( |
| 1488 const std::vector<gfx::Rect>& bounds, | 1488 const std::vector<gfx::Rect>& bounds, |
| 1489 const ui::Range& range, | 1489 const gfx::Range& range, |
| 1490 size_t* line_break_point) { | 1490 size_t* line_break_point) { |
| 1491 DCHECK(line_break_point); | 1491 DCHECK(line_break_point); |
| 1492 if (range.start() >= bounds.size() || range.is_reversed() || range.is_empty()) | 1492 if (range.start() >= bounds.size() || range.is_reversed() || range.is_empty()) |
| 1493 return false; | 1493 return false; |
| 1494 | 1494 |
| 1495 // We can't check line breaking completely from only rectangle array. Thus we | 1495 // We can't check line breaking completely from only rectangle array. Thus we |
| 1496 // assume the line breaking as the next character's y offset is larger than | 1496 // assume the line breaking as the next character's y offset is larger than |
| 1497 // a threshold. Currently the threshold is determined as minimum y offset plus | 1497 // a threshold. Currently the threshold is determined as minimum y offset plus |
| 1498 // 75% of maximum height. | 1498 // 75% of maximum height. |
| 1499 // TODO(nona): Check the threshold is reliable or not. | 1499 // TODO(nona): Check the threshold is reliable or not. |
| 1500 // TODO(nona): Bidi support. | 1500 // TODO(nona): Bidi support. |
| 1501 const size_t loop_end_idx = std::min(bounds.size(), range.end()); | 1501 const size_t loop_end_idx = std::min(bounds.size(), range.end()); |
| 1502 int max_height = 0; | 1502 int max_height = 0; |
| 1503 int min_y_offset = kint32max; | 1503 int min_y_offset = kint32max; |
| 1504 for (size_t idx = range.start(); idx < loop_end_idx; ++idx) { | 1504 for (size_t idx = range.start(); idx < loop_end_idx; ++idx) { |
| 1505 max_height = std::max(max_height, bounds[idx].height()); | 1505 max_height = std::max(max_height, bounds[idx].height()); |
| 1506 min_y_offset = std::min(min_y_offset, bounds[idx].y()); | 1506 min_y_offset = std::min(min_y_offset, bounds[idx].y()); |
| 1507 } | 1507 } |
| 1508 int line_break_threshold = min_y_offset + (max_height * 3 / 4); | 1508 int line_break_threshold = min_y_offset + (max_height * 3 / 4); |
| 1509 for (size_t idx = range.start(); idx < loop_end_idx; ++idx) { | 1509 for (size_t idx = range.start(); idx < loop_end_idx; ++idx) { |
| 1510 if (bounds[idx].y() > line_break_threshold) { | 1510 if (bounds[idx].y() > line_break_threshold) { |
| 1511 *line_break_point = idx; | 1511 *line_break_point = idx; |
| 1512 return true; | 1512 return true; |
| 1513 } | 1513 } |
| 1514 } | 1514 } |
| 1515 return false; | 1515 return false; |
| 1516 } | 1516 } |
| 1517 | 1517 |
| 1518 gfx::Rect RenderWidgetHostViewMac::GetFirstRectForCompositionRange( | 1518 gfx::Rect RenderWidgetHostViewMac::GetFirstRectForCompositionRange( |
| 1519 const ui::Range& range, | 1519 const gfx::Range& range, |
| 1520 ui::Range* actual_range) { | 1520 gfx::Range* actual_range) { |
| 1521 DCHECK(actual_range); | 1521 DCHECK(actual_range); |
| 1522 DCHECK(!composition_bounds_.empty()); | 1522 DCHECK(!composition_bounds_.empty()); |
| 1523 DCHECK(range.start() <= composition_bounds_.size()); | 1523 DCHECK(range.start() <= composition_bounds_.size()); |
| 1524 DCHECK(range.end() <= composition_bounds_.size()); | 1524 DCHECK(range.end() <= composition_bounds_.size()); |
| 1525 | 1525 |
| 1526 if (range.is_empty()) { | 1526 if (range.is_empty()) { |
| 1527 *actual_range = range; | 1527 *actual_range = range; |
| 1528 if (range.start() == composition_bounds_.size()) { | 1528 if (range.start() == composition_bounds_.size()) { |
| 1529 return gfx::Rect(composition_bounds_[range.start() - 1].right(), | 1529 return gfx::Rect(composition_bounds_[range.start() - 1].right(), |
| 1530 composition_bounds_[range.start() - 1].y(), | 1530 composition_bounds_[range.start() - 1].y(), |
| 1531 0, | 1531 0, |
| 1532 composition_bounds_[range.start() - 1].height()); | 1532 composition_bounds_[range.start() - 1].height()); |
| 1533 } else { | 1533 } else { |
| 1534 return gfx::Rect(composition_bounds_[range.start()].x(), | 1534 return gfx::Rect(composition_bounds_[range.start()].x(), |
| 1535 composition_bounds_[range.start()].y(), | 1535 composition_bounds_[range.start()].y(), |
| 1536 0, | 1536 0, |
| 1537 composition_bounds_[range.start()].height()); | 1537 composition_bounds_[range.start()].height()); |
| 1538 } | 1538 } |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 size_t end_idx; | 1541 size_t end_idx; |
| 1542 if (!GetLineBreakIndex(composition_bounds_, range, &end_idx)) { | 1542 if (!GetLineBreakIndex(composition_bounds_, range, &end_idx)) { |
| 1543 end_idx = range.end(); | 1543 end_idx = range.end(); |
| 1544 } | 1544 } |
| 1545 *actual_range = ui::Range(range.start(), end_idx); | 1545 *actual_range = gfx::Range(range.start(), end_idx); |
| 1546 gfx::Rect rect = composition_bounds_[range.start()]; | 1546 gfx::Rect rect = composition_bounds_[range.start()]; |
| 1547 for (size_t i = range.start() + 1; i < end_idx; ++i) { | 1547 for (size_t i = range.start() + 1; i < end_idx; ++i) { |
| 1548 rect.Union(composition_bounds_[i]); | 1548 rect.Union(composition_bounds_[i]); |
| 1549 } | 1549 } |
| 1550 return rect; | 1550 return rect; |
| 1551 } | 1551 } |
| 1552 | 1552 |
| 1553 ui::Range RenderWidgetHostViewMac::ConvertCharacterRangeToCompositionRange( | 1553 gfx::Range RenderWidgetHostViewMac::ConvertCharacterRangeToCompositionRange( |
| 1554 const ui::Range& request_range) { | 1554 const gfx::Range& request_range) { |
| 1555 if (composition_range_.is_empty()) | 1555 if (composition_range_.is_empty()) |
| 1556 return ui::Range::InvalidRange(); | 1556 return gfx::Range::InvalidRange(); |
| 1557 | 1557 |
| 1558 if (request_range.is_reversed()) | 1558 if (request_range.is_reversed()) |
| 1559 return ui::Range::InvalidRange(); | 1559 return gfx::Range::InvalidRange(); |
| 1560 | 1560 |
| 1561 if (request_range.start() < composition_range_.start() || | 1561 if (request_range.start() < composition_range_.start() || |
| 1562 request_range.start() > composition_range_.end() || | 1562 request_range.start() > composition_range_.end() || |
| 1563 request_range.end() > composition_range_.end()) { | 1563 request_range.end() > composition_range_.end()) { |
| 1564 return ui::Range::InvalidRange(); | 1564 return gfx::Range::InvalidRange(); |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 return ui::Range( | 1567 return gfx::Range( |
| 1568 request_range.start() - composition_range_.start(), | 1568 request_range.start() - composition_range_.start(), |
| 1569 request_range.end() - composition_range_.start()); | 1569 request_range.end() - composition_range_.start()); |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( | 1572 bool RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange( |
| 1573 NSRange range, | 1573 NSRange range, |
| 1574 NSRect* rect, | 1574 NSRect* rect, |
| 1575 NSRange* actual_range) { | 1575 NSRange* actual_range) { |
| 1576 DCHECK(rect); | 1576 DCHECK(rect); |
| 1577 // This exists to make IMEs more responsive, see http://crbug.com/115920 | 1577 // This exists to make IMEs more responsive, see http://crbug.com/115920 |
| 1578 TRACE_EVENT0("browser", | 1578 TRACE_EVENT0("browser", |
| 1579 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); | 1579 "RenderWidgetHostViewMac::GetFirstRectForCharacterRange"); |
| 1580 | 1580 |
| 1581 // If requested range is same as caret location, we can just return it. | 1581 // If requested range is same as caret location, we can just return it. |
| 1582 if (selection_range_.is_empty() && ui::Range(range) == selection_range_) { | 1582 if (selection_range_.is_empty() && gfx::Range(range) == selection_range_) { |
| 1583 if (actual_range) | 1583 if (actual_range) |
| 1584 *actual_range = range; | 1584 *actual_range = range; |
| 1585 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); | 1585 *rect = NSRectFromCGRect(caret_rect_.ToCGRect()); |
| 1586 return true; | 1586 return true; |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 const ui::Range request_range_in_composition = | 1589 const gfx::Range request_range_in_composition = |
| 1590 ConvertCharacterRangeToCompositionRange(ui::Range(range)); | 1590 ConvertCharacterRangeToCompositionRange(gfx::Range(range)); |
| 1591 if (request_range_in_composition == ui::Range::InvalidRange()) | 1591 if (request_range_in_composition == gfx::Range::InvalidRange()) |
| 1592 return false; | 1592 return false; |
| 1593 | 1593 |
| 1594 // If firstRectForCharacterRange in WebFrame is failed in renderer, | 1594 // If firstRectForCharacterRange in WebFrame is failed in renderer, |
| 1595 // ImeCompositionRangeChanged will be sent with empty vector. | 1595 // ImeCompositionRangeChanged will be sent with empty vector. |
| 1596 if (composition_bounds_.empty()) | 1596 if (composition_bounds_.empty()) |
| 1597 return false; | 1597 return false; |
| 1598 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); | 1598 DCHECK_EQ(composition_bounds_.size(), composition_range_.length()); |
| 1599 | 1599 |
| 1600 ui::Range ui_actual_range; | 1600 gfx::Range ui_actual_range; |
| 1601 *rect = NSRectFromCGRect(GetFirstRectForCompositionRange( | 1601 *rect = NSRectFromCGRect(GetFirstRectForCompositionRange( |
| 1602 request_range_in_composition, | 1602 request_range_in_composition, |
| 1603 &ui_actual_range).ToCGRect()); | 1603 &ui_actual_range).ToCGRect()); |
| 1604 if (actual_range) { | 1604 if (actual_range) { |
| 1605 *actual_range = ui::Range( | 1605 *actual_range = gfx::Range( |
| 1606 composition_range_.start() + ui_actual_range.start(), | 1606 composition_range_.start() + ui_actual_range.start(), |
| 1607 composition_range_.start() + ui_actual_range.end()).ToNSRange(); | 1607 composition_range_.start() + ui_actual_range.end()).ToNSRange(); |
| 1608 } | 1608 } |
| 1609 return true; | 1609 return true; |
| 1610 } | 1610 } |
| 1611 | 1611 |
| 1612 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( | 1612 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( |
| 1613 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 1613 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 1614 int gpu_host_id) { | 1614 int gpu_host_id) { |
| 1615 TRACE_EVENT0("browser", | 1615 TRACE_EVENT0("browser", |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2323 // the keydown event, so that we can retain all necessary informations, such | 2323 // the keydown event, so that we can retain all necessary informations, such |
| 2324 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to | 2324 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to |
| 2325 // prevent the browser from handling it again. | 2325 // prevent the browser from handling it again. |
| 2326 // Note that, |textToBeInserted_| is a UTF-16 string, but it's fine to only | 2326 // Note that, |textToBeInserted_| is a UTF-16 string, but it's fine to only |
| 2327 // handle BMP characters here, as we can always insert non-BMP characters as | 2327 // handle BMP characters here, as we can always insert non-BMP characters as |
| 2328 // text. | 2328 // text. |
| 2329 BOOL textInserted = NO; | 2329 BOOL textInserted = NO; |
| 2330 if (textToBeInserted_.length() > | 2330 if (textToBeInserted_.length() > |
| 2331 ((hasMarkedText_ || oldHasMarkedText) ? 0u : 1u)) { | 2331 ((hasMarkedText_ || oldHasMarkedText) ? 0u : 1u)) { |
| 2332 widgetHost->ImeConfirmComposition( | 2332 widgetHost->ImeConfirmComposition( |
| 2333 textToBeInserted_, ui::Range::InvalidRange(), false); | 2333 textToBeInserted_, gfx::Range::InvalidRange(), false); |
| 2334 textInserted = YES; | 2334 textInserted = YES; |
| 2335 } | 2335 } |
| 2336 | 2336 |
| 2337 // Updates or cancels the composition. If some text has been inserted, then | 2337 // Updates or cancels the composition. If some text has been inserted, then |
| 2338 // we don't need to cancel the composition explicitly. | 2338 // we don't need to cancel the composition explicitly. |
| 2339 if (hasMarkedText_ && markedText_.length()) { | 2339 if (hasMarkedText_ && markedText_.length()) { |
| 2340 // Sends the updated marked text to the renderer so it can update the | 2340 // Sends the updated marked text to the renderer so it can update the |
| 2341 // composition node in WebKit. | 2341 // composition node in WebKit. |
| 2342 // When marked text is available, |selectedRange_| will be the range being | 2342 // When marked text is available, |selectedRange_| will be the range being |
| 2343 // selected inside the marked text. | 2343 // selected inside the marked text. |
| 2344 widgetHost->ImeSetComposition(markedText_, underlines_, | 2344 widgetHost->ImeSetComposition(markedText_, underlines_, |
| 2345 selectedRange_.location, | 2345 selectedRange_.location, |
| 2346 NSMaxRange(selectedRange_)); | 2346 NSMaxRange(selectedRange_)); |
| 2347 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { | 2347 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { |
| 2348 if (unmarkTextCalled_) { | 2348 if (unmarkTextCalled_) { |
| 2349 widgetHost->ImeConfirmComposition( | 2349 widgetHost->ImeConfirmComposition( |
| 2350 string16(), ui::Range::InvalidRange(), false); | 2350 string16(), gfx::Range::InvalidRange(), false); |
| 2351 } else { | 2351 } else { |
| 2352 widgetHost->ImeCancelComposition(); | 2352 widgetHost->ImeCancelComposition(); |
| 2353 } | 2353 } |
| 2354 } | 2354 } |
| 2355 | 2355 |
| 2356 // If the key event was handled by the input method but it also generated some | 2356 // If the key event was handled by the input method but it also generated some |
| 2357 // edit commands, then we need to send the real key event and corresponding | 2357 // edit commands, then we need to send the real key event and corresponding |
| 2358 // edit commands here. This usually occurs when the input method wants to | 2358 // edit commands here. This usually occurs when the input method wants to |
| 2359 // finish current composition session but still wants the application to | 2359 // finish current composition session but still wants the application to |
| 2360 // handle the key event. See http://crbug.com/48161 for reference. | 2360 // handle the key event. See http://crbug.com/48161 for reference. |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3420 // text when it cancels an ongoing composition, i.e. I have never seen an | 3420 // text when it cancels an ongoing composition, i.e. I have never seen an |
| 3421 // input method calls this method. | 3421 // input method calls this method. |
| 3422 hasMarkedText_ = NO; | 3422 hasMarkedText_ = NO; |
| 3423 markedText_.clear(); | 3423 markedText_.clear(); |
| 3424 underlines_.clear(); | 3424 underlines_.clear(); |
| 3425 | 3425 |
| 3426 // If we are handling a key down event, then ConfirmComposition() will be | 3426 // If we are handling a key down event, then ConfirmComposition() will be |
| 3427 // called in keyEvent: method. | 3427 // called in keyEvent: method. |
| 3428 if (!handlingKeyDown_) { | 3428 if (!handlingKeyDown_) { |
| 3429 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 3429 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 3430 string16(), ui::Range::InvalidRange(), false); | 3430 string16(), gfx::Range::InvalidRange(), false); |
| 3431 } else { | 3431 } else { |
| 3432 unmarkTextCalled_ = YES; | 3432 unmarkTextCalled_ = YES; |
| 3433 } | 3433 } |
| 3434 } | 3434 } |
| 3435 | 3435 |
| 3436 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange | 3436 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange |
| 3437 replacementRange:(NSRange)replacementRange { | 3437 replacementRange:(NSRange)replacementRange { |
| 3438 // An input method updates the composition string. | 3438 // An input method updates the composition string. |
| 3439 // We send the given text and range to the renderer so it can update the | 3439 // We send the given text and range to the renderer so it can update the |
| 3440 // composition node of WebKit. | 3440 // composition node of WebKit. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3513 // Text inserting might be initiated by other source instead of keyboard | 3513 // Text inserting might be initiated by other source instead of keyboard |
| 3514 // events, such as the Characters dialog. In this case the text should be | 3514 // events, such as the Characters dialog. In this case the text should be |
| 3515 // sent as an input method event as well. | 3515 // sent as an input method event as well. |
| 3516 // TODO(suzhe): It's hard for us to support replacementRange without accessing | 3516 // TODO(suzhe): It's hard for us to support replacementRange without accessing |
| 3517 // the full web content. | 3517 // the full web content. |
| 3518 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; | 3518 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; |
| 3519 NSString* im_text = isAttributedString ? [string string] : string; | 3519 NSString* im_text = isAttributedString ? [string string] : string; |
| 3520 if (handlingKeyDown_) { | 3520 if (handlingKeyDown_) { |
| 3521 textToBeInserted_.append(base::SysNSStringToUTF16(im_text)); | 3521 textToBeInserted_.append(base::SysNSStringToUTF16(im_text)); |
| 3522 } else { | 3522 } else { |
| 3523 ui::Range replacement_range(replacementRange); | 3523 gfx::Range replacement_range(replacementRange); |
| 3524 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 3524 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 3525 base::SysNSStringToUTF16(im_text), replacement_range, false); | 3525 base::SysNSStringToUTF16(im_text), replacement_range, false); |
| 3526 } | 3526 } |
| 3527 | 3527 |
| 3528 // Inserting text will delete all marked text automatically. | 3528 // Inserting text will delete all marked text automatically. |
| 3529 hasMarkedText_ = NO; | 3529 hasMarkedText_ = NO; |
| 3530 } | 3530 } |
| 3531 | 3531 |
| 3532 - (void)insertText:(id)string { | 3532 - (void)insertText:(id)string { |
| 3533 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; | 3533 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3658 // Should not call [self unmarkText] here, because it'll send unnecessary | 3658 // Should not call [self unmarkText] here, because it'll send unnecessary |
| 3659 // cancel composition IPC message to the renderer. | 3659 // cancel composition IPC message to the renderer. |
| 3660 } | 3660 } |
| 3661 | 3661 |
| 3662 - (void)confirmComposition { | 3662 - (void)confirmComposition { |
| 3663 if (!hasMarkedText_) | 3663 if (!hasMarkedText_) |
| 3664 return; | 3664 return; |
| 3665 | 3665 |
| 3666 if (renderWidgetHostView_->render_widget_host_) | 3666 if (renderWidgetHostView_->render_widget_host_) |
| 3667 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 3667 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 3668 string16(), ui::Range::InvalidRange(), false); | 3668 string16(), gfx::Range::InvalidRange(), false); |
| 3669 | 3669 |
| 3670 [self cancelComposition]; | 3670 [self cancelComposition]; |
| 3671 } | 3671 } |
| 3672 | 3672 |
| 3673 - (void)setPluginImeActive:(BOOL)active { | 3673 - (void)setPluginImeActive:(BOOL)active { |
| 3674 if (active == pluginImeActive_) | 3674 if (active == pluginImeActive_) |
| 3675 return; | 3675 return; |
| 3676 | 3676 |
| 3677 pluginImeActive_ = active; | 3677 pluginImeActive_ = active; |
| 3678 if (!active) { | 3678 if (!active) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3846 return YES; | 3846 return YES; |
| 3847 } | 3847 } |
| 3848 | 3848 |
| 3849 - (BOOL)isOpaque { | 3849 - (BOOL)isOpaque { |
| 3850 if (renderWidgetHostView_->use_core_animation_) | 3850 if (renderWidgetHostView_->use_core_animation_) |
| 3851 return YES; | 3851 return YES; |
| 3852 return [super isOpaque]; | 3852 return [super isOpaque]; |
| 3853 } | 3853 } |
| 3854 | 3854 |
| 3855 @end | 3855 @end |
| OLD | NEW |