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

Side by Side Diff: ppapi/examples/ime/ime.cc

Issue 8244005: Fix for checkdeps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h"
10 #include "ppapi/c/dev/ppb_console_dev.h" 9 #include "ppapi/c/dev/ppb_console_dev.h"
11 #include "ppapi/c/dev/ppb_cursor_control_dev.h" 10 #include "ppapi/c/dev/ppb_cursor_control_dev.h"
12 #include "ppapi/cpp/completion_callback.h" 11 #include "ppapi/cpp/completion_callback.h"
13 #include "ppapi/cpp/dev/font_dev.h" 12 #include "ppapi/cpp/dev/font_dev.h"
14 #include "ppapi/cpp/dev/ime_input_event_dev.h" 13 #include "ppapi/cpp/dev/ime_input_event_dev.h"
15 #include "ppapi/cpp/dev/text_input_dev.h" 14 #include "ppapi/cpp/dev/text_input_dev.h"
16 #include "ppapi/cpp/graphics_2d.h" 15 #include "ppapi/cpp/graphics_2d.h"
17 #include "ppapi/cpp/image_data.h" 16 #include "ppapi/cpp/image_data.h"
18 #include "ppapi/cpp/input_event.h" 17 #include "ppapi/cpp/input_event.h"
19 #include "ppapi/cpp/instance.h" 18 #include "ppapi/cpp/instance.h"
20 #include "ppapi/cpp/module.h" 19 #include "ppapi/cpp/module.h"
21 #include "ppapi/cpp/rect.h" 20 #include "ppapi/cpp/rect.h"
22 #include "ppapi/cpp/size.h" 21 #include "ppapi/cpp/size.h"
23 #include "ui/base/keycodes/keyboard_codes.h"
24 22
25 namespace { 23 namespace {
26 24
25 // Extracted from: ui/base/keycode/keyboard_codes.h
26 enum {
27 VKEY_BACK = 0x08,
28 VKEY_DELETE = 0x2E,
29 VKEY_LEFT = 0x25,
30 VKEY_UP = 0x26,
31 VKEY_RIGHT = 0x27,
32 VKEY_DOWN = 0x28,
33 };
34
27 const uint32_t kTextfieldBgColor = 0xffffffff; 35 const uint32_t kTextfieldBgColor = 0xffffffff;
28 const uint32_t kTextfieldTextColor = 0xff000000; 36 const uint32_t kTextfieldTextColor = 0xff000000;
29 const uint32_t kTextfieldCaretColor = 0xff000000; 37 const uint32_t kTextfieldCaretColor = 0xff000000;
30 const uint32_t kTextfieldPreeditTextColor = 0xffff0000; 38 const uint32_t kTextfieldPreeditTextColor = 0xffff0000;
31 const uint32_t kTextfieldUnderlineColorMain = 0xffff0000; 39 const uint32_t kTextfieldUnderlineColorMain = 0xffff0000;
32 const uint32_t kTextfieldUnderlineColorSub = 0xffddaaaa; 40 const uint32_t kTextfieldUnderlineColorSub = 0xffddaaaa;
33 41
34 void FillRect(pp::ImageData* image, 42 void FillRect(pp::ImageData* image,
35 int left, int top, int width, int height, 43 int left, int top, int width, int height,
36 uint32_t color) { 44 uint32_t color) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 int target_segment_; 316 int target_segment_;
309 }; 317 };
310 318
311 class MyInstance : public pp::Instance { 319 class MyInstance : public pp::Instance {
312 public: 320 public:
313 explicit MyInstance(PP_Instance instance) 321 explicit MyInstance(PP_Instance instance)
314 : pp::Instance(instance), 322 : pp::Instance(instance),
315 status_handler_(new TextFieldStatusHandler) { 323 status_handler_(new TextFieldStatusHandler) {
316 } 324 }
317 325
326 ~MyInstance() {
327 delete status_handler_;
328 }
329
318 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 330 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
319 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 331 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
320 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 332 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
321 333
322 for (uint32_t i = 0; i < argc; ++i) { 334 for (uint32_t i = 0; i < argc; ++i) {
323 if (argn[i] == std::string("ime")) { 335 if (argn[i] == std::string("ime")) {
324 if (argv[i] == std::string("no")) { 336 if (argv[i] == std::string("no")) {
325 // Example of NO-IME plugins (e.g., games). 337 // Example of NO-IME plugins (e.g., games).
326 // 338 //
327 // When a plugin never wants to accept text input, at initialization 339 // When a plugin never wants to accept text input, at initialization
328 // explicitly turn off the text input feature by calling: 340 // explicitly turn off the text input feature by calling:
329 pp::TextInput_Dev(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE); 341 pp::TextInput_Dev(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE);
330 } else if (argv[i] == std::string("unaware")) { 342 } else if (argv[i] == std::string("unaware")) {
331 // Demonstrating the behavior of IME-unaware plugins. 343 // Demonstrating the behavior of IME-unaware plugins.
332 // Never call any text input related APIs. 344 // Never call any text input related APIs.
333 // 345 //
334 // In such a case, the plugin is assumed to always accept text input. 346 // In such a case, the plugin is assumed to always accept text input.
335 // For example, when the plugin is focused in touch devices a virtual 347 // For example, when the plugin is focused in touch devices a virtual
336 // keyboard may pop up, or in environment IME is used, users can type 348 // keyboard may pop up, or in environment IME is used, users can type
337 // text via IME on the plugin. The characters are delivered to the 349 // text via IME on the plugin. The characters are delivered to the
338 // plugin via PP_INPUTEVENT_TYPE_CHAR events. 350 // plugin via PP_INPUTEVENT_TYPE_CHAR events.
339 } else if (argv[i] == std::string("caretmove")) { 351 } else if (argv[i] == std::string("caretmove")) {
340 // Demonstrating the behavior of plugins with limited IME support. 352 // Demonstrating the behavior of plugins with limited IME support.
341 // 353 //
342 // It uses SetTextInputType() and UpdateCaretPosition() API to notify 354 // It uses SetTextInputType() and UpdateCaretPosition() API to notify
343 // text input status to the browser, but unable to handle inline 355 // text input status to the browser, but unable to handle inline
344 // compositions. By using the notified information. the browser can, 356 // compositions. By using the notified information. the browser can,
345 // say, show virtual keyboards or IMEs only at appropriate timing 357 // say, show virtual keyboards or IMEs only at appropriate timing
346 // that the plugin does need to accept text input. 358 // that the plugin does need to accept text input.
347 status_handler_.reset(new TextFieldStatusNotifyingHanlder(this)); 359 delete status_handler_;
360 status_handler_ = new TextFieldStatusNotifyingHanlder(this);
348 } else if (argv[i] == std::string("full")) { 361 } else if (argv[i] == std::string("full")) {
349 // Demonstrating the behavior of plugins fully supporting IME. 362 // Demonstrating the behavior of plugins fully supporting IME.
350 // 363 //
351 // It notifies updates of caret positions to the browser, 364 // It notifies updates of caret positions to the browser,
352 // and handles all text input events by itself. 365 // and handles all text input events by itself.
353 status_handler_.reset(new TextFieldStatusNotifyingHanlder(this)); 366 delete status_handler_;
367 status_handler_ = new TextFieldStatusNotifyingHanlder(this);
354 RequestInputEvents(PP_INPUTEVENT_CLASS_IME); 368 RequestInputEvents(PP_INPUTEVENT_CLASS_IME);
355 } 369 }
356 break; 370 break;
357 } 371 }
358 } 372 }
359 373
360 textfield_.push_back(MyTextField(this, status_handler_.get(), 374 textfield_.push_back(MyTextField(this, status_handler_,
361 10, 10, 300, 20)); 375 10, 10, 300, 20));
362 textfield_.back().SetText("Hello"); 376 textfield_.back().SetText("Hello");
363 textfield_.push_back(MyTextField(this, status_handler_.get(), 377 textfield_.push_back(MyTextField(this, status_handler_,
364 30, 100, 300, 20)); 378 30, 100, 300, 20));
365 textfield_.back().SetText("World"); 379 textfield_.back().SetText("World");
366 return true; 380 return true;
367 } 381 }
368 382
369 protected: 383 protected:
370 virtual bool HandleInputEvent(const pp::InputEvent& event) { 384 virtual bool HandleInputEvent(const pp::InputEvent& event) {
371 bool ret = false; 385 bool ret = false;
372 switch (event.GetType()) { 386 switch (event.GetType()) {
373 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { 387 case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 0, NULL); 515 0, NULL);
502 return true; 516 return true;
503 } 517 }
504 518
505 bool OnKeyDown(const pp::KeyboardInputEvent& ev) { 519 bool OnKeyDown(const pp::KeyboardInputEvent& ev) {
506 for (std::vector<MyTextField>::iterator it = textfield_.begin(); 520 for (std::vector<MyTextField>::iterator it = textfield_.begin();
507 it != textfield_.end(); 521 it != textfield_.end();
508 ++it) { 522 ++it) {
509 if (it->Focused()) { 523 if (it->Focused()) {
510 switch (ev.GetKeyCode()) { 524 switch (ev.GetKeyCode()) {
511 case ui::VKEY_LEFT: 525 case VKEY_LEFT:
512 it->KeyLeft(); 526 it->KeyLeft();
513 break; 527 break;
514 case ui::VKEY_RIGHT: 528 case VKEY_RIGHT:
515 it->KeyRight(); 529 it->KeyRight();
516 break; 530 break;
517 case ui::VKEY_DELETE: 531 case VKEY_DELETE:
518 it->KeyDelete(); 532 it->KeyDelete();
519 break; 533 break;
520 case ui::VKEY_BACK: 534 case VKEY_BACK:
521 it->KeyBackspace(); 535 it->KeyBackspace();
522 break; 536 break;
523 } 537 }
524 return true; 538 return true;
525 } 539 }
526 } 540 }
527 return false; 541 return false;
528 } 542 }
529 543
530 bool OnChar(const pp::KeyboardInputEvent& ev) { 544 bool OnChar(const pp::KeyboardInputEvent& ev) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // Prints a debug message. 592 // Prints a debug message.
579 void Log(const pp::Var& value) { 593 void Log(const pp::Var& value) {
580 const PPB_Console_Dev* console = reinterpret_cast<const PPB_Console_Dev*>( 594 const PPB_Console_Dev* console = reinterpret_cast<const PPB_Console_Dev*>(
581 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); 595 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE));
582 if (!console) 596 if (!console)
583 return; 597 return;
584 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); 598 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var());
585 } 599 }
586 600
587 // IME Control interface. 601 // IME Control interface.
588 scoped_ptr<TextFieldStatusHandler> status_handler_; 602 TextFieldStatusHandler* status_handler_;
589 603
590 // Remembers the size of this instance. 604 // Remembers the size of this instance.
591 pp::Size last_size_; 605 pp::Size last_size_;
592 606
593 // Holds instances of text fields. 607 // Holds instances of text fields.
594 std::vector<MyTextField> textfield_; 608 std::vector<MyTextField> textfield_;
595 }; 609 };
596 610
597 class MyModule : public pp::Module { 611 class MyModule : public pp::Module {
598 virtual pp::Instance* CreateInstance(PP_Instance instance) { 612 virtual pp::Instance* CreateInstance(PP_Instance instance) {
599 return new MyInstance(instance); 613 return new MyInstance(instance);
600 } 614 }
601 }; 615 };
602 616
603 namespace pp { 617 namespace pp {
604 618
605 Module* CreateModule() { 619 Module* CreateModule() {
606 return new MyModule(); 620 return new MyModule();
607 } 621 }
608 622
609 } // namespace pp 623 } // namespace pp
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698