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 <string> | 5 #include <string> |
6 #include <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 9 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
10 #include "ppapi/c/ppb_console.h" | 10 #include "ppapi/c/ppb_console.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 // Update current composition text. | 241 // Update current composition text. |
242 void SetComposition( | 242 void SetComposition( |
243 const std::string& text, | 243 const std::string& text, |
244 const std::vector< std::pair<uint32_t, uint32_t> >& segments, | 244 const std::vector< std::pair<uint32_t, uint32_t> >& segments, |
245 int32_t target_segment, | 245 int32_t target_segment, |
246 const std::pair<uint32_t, uint32_t>& selection) { | 246 const std::pair<uint32_t, uint32_t>& selection) { |
247 if (HasSelection() && !text.empty()) | 247 if (HasSelection() && !text.empty()) |
248 InsertText(""); | 248 InsertText(std::string()); |
249 composition_ = text; | 249 composition_ = text; |
250 segments_ = segments; | 250 segments_ = segments; |
251 target_segment_ = target_segment; | 251 target_segment_ = target_segment; |
252 composition_selection_ = selection; | 252 composition_selection_ = selection; |
253 CaretPosChanged(); | 253 CaretPosChanged(); |
254 } | 254 } |
255 | 255 |
256 // Is the text field focused? | 256 // Is the text field focused? |
257 bool Focused() const { | 257 bool Focused() const { |
258 return caret_pos_ != std::string::npos; | 258 return caret_pos_ != std::string::npos; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Move the anchor if the shift key is not pressed. | 337 // Move the anchor if the shift key is not pressed. |
338 if (!shift) | 338 if (!shift) |
339 anchor_pos_ = caret_pos_; | 339 anchor_pos_ = caret_pos_; |
340 CaretPosChanged(); | 340 CaretPosChanged(); |
341 } | 341 } |
342 | 342 |
343 void KeyDelete() { | 343 void KeyDelete() { |
344 if (!Focused()) | 344 if (!Focused()) |
345 return; | 345 return; |
346 if (HasSelection()) { | 346 if (HasSelection()) { |
347 InsertText(""); | 347 InsertText(std::string()); |
348 } else { | 348 } else { |
349 size_t i = GetNextCharOffsetUtf8(utf8_text_, caret_pos_); | 349 size_t i = GetNextCharOffsetUtf8(utf8_text_, caret_pos_); |
350 utf8_text_.erase(caret_pos_, i - caret_pos_); | 350 utf8_text_.erase(caret_pos_, i - caret_pos_); |
351 CaretPosChanged(); | 351 CaretPosChanged(); |
352 } | 352 } |
353 } | 353 } |
354 | 354 |
355 void KeyBackspace() { | 355 void KeyBackspace() { |
356 if (!Focused()) | 356 if (!Focused()) |
357 return; | 357 return; |
358 if (HasSelection()) { | 358 if (HasSelection()) { |
359 InsertText(""); | 359 InsertText(std::string()); |
360 } else if (caret_pos_ != 0) { | 360 } else if (caret_pos_ != 0) { |
361 size_t i = GetPrevCharOffsetUtf8(utf8_text_, caret_pos_); | 361 size_t i = GetPrevCharOffsetUtf8(utf8_text_, caret_pos_); |
362 utf8_text_.erase(i, caret_pos_ - i); | 362 utf8_text_.erase(i, caret_pos_ - i); |
363 caret_pos_ = anchor_pos_ = i; | 363 caret_pos_ = anchor_pos_ = i; |
364 CaretPosChanged(); | 364 CaretPosChanged(); |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 private: | 368 private: |
369 // Notify the plugin instance that the caret position has changed. | 369 // Notify the plugin instance that the caret position has changed. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 } | 558 } |
559 } | 559 } |
560 return false; | 560 return false; |
561 } | 561 } |
562 | 562 |
563 bool OnCompositionEnd(const pp::IMEInputEvent_Dev& ev) { | 563 bool OnCompositionEnd(const pp::IMEInputEvent_Dev& ev) { |
564 for (std::vector<MyTextField>::iterator it = textfield_.begin(); | 564 for (std::vector<MyTextField>::iterator it = textfield_.begin(); |
565 it != textfield_.end(); | 565 it != textfield_.end(); |
566 ++it) { | 566 ++it) { |
567 if (it->Focused()) { | 567 if (it->Focused()) { |
568 it->SetComposition("", std::vector< std::pair<uint32_t, uint32_t> >(), | 568 it->SetComposition(std::string(), |
569 0, std::make_pair(0, 0)); | 569 std::vector<std::pair<uint32_t, uint32_t> >(), |
| 570 0, |
| 571 std::make_pair(0, 0)); |
570 return true; | 572 return true; |
571 } | 573 } |
572 } | 574 } |
573 return false; | 575 return false; |
574 } | 576 } |
575 | 577 |
576 bool OnMouseDown(const pp::MouseInputEvent& ev) { | 578 bool OnMouseDown(const pp::MouseInputEvent& ev) { |
577 dragging_ = true; | 579 dragging_ = true; |
578 | 580 |
579 bool anyone_focused = false; | 581 bool anyone_focused = false; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 } | 729 } |
728 }; | 730 }; |
729 | 731 |
730 namespace pp { | 732 namespace pp { |
731 | 733 |
732 Module* CreateModule() { | 734 Module* CreateModule() { |
733 return new MyModule(); | 735 return new MyModule(); |
734 } | 736 } |
735 | 737 |
736 } // namespace pp | 738 } // namespace pp |
OLD | NEW |