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

Side by Side Diff: xfa/fwl/core/ifwl_pushbutton.cpp

Issue 2467993003: Merge delegates into IFWL_* classes. (Closed)
Patch Set: Add const version Created 4 years, 1 month 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
« no previous file with comments | « xfa/fwl/core/ifwl_pushbutton.h ('k') | xfa/fwl/core/ifwl_scrollbar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/core/ifwl_pushbutton.h" 7 #include "xfa/fwl/core/ifwl_pushbutton.h"
8 8
9 #include "third_party/base/ptr_util.h" 9 #include "third_party/base/ptr_util.h"
10 #include "xfa/fde/tto/fde_textout.h" 10 #include "xfa/fde/tto/fde_textout.h"
11 #include "xfa/fwl/core/cfwl_message.h" 11 #include "xfa/fwl/core/cfwl_message.h"
12 #include "xfa/fwl/core/cfwl_themebackground.h" 12 #include "xfa/fwl/core/cfwl_themebackground.h"
13 #include "xfa/fwl/core/cfwl_themetext.h" 13 #include "xfa/fwl/core/cfwl_themetext.h"
14 #include "xfa/fwl/core/fwl_noteimp.h" 14 #include "xfa/fwl/core/fwl_noteimp.h"
15 #include "xfa/fwl/core/ifwl_pushbutton.h" 15 #include "xfa/fwl/core/ifwl_pushbutton.h"
16 #include "xfa/fwl/core/ifwl_themeprovider.h" 16 #include "xfa/fwl/core/ifwl_themeprovider.h"
17 17
18 IFWL_PushButton::IFWL_PushButton(const IFWL_App* app, 18 IFWL_PushButton::IFWL_PushButton(const IFWL_App* app,
19 const CFWL_WidgetImpProperties& properties) 19 const CFWL_WidgetImpProperties& properties)
20 : IFWL_Widget(app, properties, nullptr), 20 : IFWL_Widget(app, properties, nullptr),
21 m_bBtnDown(FALSE), 21 m_bBtnDown(FALSE),
22 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), 22 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine),
23 m_iTTOAlign(FDE_TTOALIGNMENT_Center) { 23 m_iTTOAlign(FDE_TTOALIGNMENT_Center) {
24 m_rtClient.Set(0, 0, 0, 0); 24 m_rtClient.Set(0, 0, 0, 0);
25 m_rtCaption.Set(0, 0, 0, 0); 25 m_rtCaption.Set(0, 0, 0, 0);
26
27 SetDelegate(pdfium::MakeUnique<CFWL_PushButtonImpDelegate>(this));
28 } 26 }
29 27
30 IFWL_PushButton::~IFWL_PushButton() {} 28 IFWL_PushButton::~IFWL_PushButton() {}
31 29
32 FWL_Type IFWL_PushButton::GetClassID() const { 30 FWL_Type IFWL_PushButton::GetClassID() const {
33 return FWL_Type::PushButton; 31 return FWL_Type::PushButton;
34 } 32 }
35 33
36 FWL_Error IFWL_PushButton::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { 34 FWL_Error IFWL_PushButton::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
37 if (bAutoSize) { 35 if (bAutoSize) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 break; 372 break;
375 } 373 }
376 default: {} 374 default: {}
377 } 375 }
378 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; 376 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
379 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { 377 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) {
380 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; 378 m_dwTTOStyles |= FDE_TTOSTYLE_RTL;
381 } 379 }
382 } 380 }
383 381
384 CFWL_PushButtonImpDelegate::CFWL_PushButtonImpDelegate(IFWL_PushButton* pOwner) 382 void IFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) {
385 : m_pOwner(pOwner) {}
386
387 void CFWL_PushButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {
388 if (!pMessage) 383 if (!pMessage)
389 return; 384 return;
390 if (!m_pOwner->IsEnabled()) 385 if (!IsEnabled())
391 return; 386 return;
392 387
393 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); 388 CFWL_MessageType dwMsgCode = pMessage->GetClassID();
394 switch (dwMsgCode) { 389 switch (dwMsgCode) {
395 case CFWL_MessageType::SetFocus: { 390 case CFWL_MessageType::SetFocus:
396 OnFocusChanged(pMessage, TRUE); 391 OnFocusChanged(pMessage, TRUE);
397 break; 392 break;
398 } 393 case CFWL_MessageType::KillFocus:
399 case CFWL_MessageType::KillFocus: {
400 OnFocusChanged(pMessage, FALSE); 394 OnFocusChanged(pMessage, FALSE);
401 break; 395 break;
402 }
403 case CFWL_MessageType::Mouse: { 396 case CFWL_MessageType::Mouse: {
404 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); 397 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
405 switch (pMsg->m_dwCmd) { 398 switch (pMsg->m_dwCmd) {
406 case FWL_MouseCommand::LeftButtonDown: { 399 case FWL_MouseCommand::LeftButtonDown:
407 OnLButtonDown(pMsg); 400 OnLButtonDown(pMsg);
408 break; 401 break;
409 } 402 case FWL_MouseCommand::LeftButtonUp:
410 case FWL_MouseCommand::LeftButtonUp: {
411 OnLButtonUp(pMsg); 403 OnLButtonUp(pMsg);
412 break; 404 break;
413 } 405 case FWL_MouseCommand::Move:
414 case FWL_MouseCommand::Move: {
415 OnMouseMove(pMsg); 406 OnMouseMove(pMsg);
416 break; 407 break;
417 } 408 case FWL_MouseCommand::Leave:
418 case FWL_MouseCommand::Leave: {
419 OnMouseLeave(pMsg); 409 OnMouseLeave(pMsg);
420 break; 410 break;
421 }
422 default: 411 default:
423 break; 412 break;
424 } 413 }
425 break; 414 break;
426 } 415 }
427 case CFWL_MessageType::Key: { 416 case CFWL_MessageType::Key: {
428 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); 417 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage);
429 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) 418 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown)
430 OnKeyDown(pKey); 419 OnKeyDown(pKey);
431 break; 420 break;
432 } 421 }
433 default: { break; } 422 default:
423 break;
434 } 424 }
435 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); 425 IFWL_Widget::OnProcessMessage(pMessage);
436 } 426 }
437 427
438 void CFWL_PushButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} 428 void IFWL_PushButton::OnDrawWidget(CFX_Graphics* pGraphics,
439 429 const CFX_Matrix* pMatrix) {
440 void CFWL_PushButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, 430 DrawWidget(pGraphics, pMatrix);
441 const CFX_Matrix* pMatrix) {
442 m_pOwner->DrawWidget(pGraphics, pMatrix);
443 } 431 }
444 432
445 void CFWL_PushButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, 433 void IFWL_PushButton::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) {
446 FX_BOOL bSet) { 434 if (bSet)
447 if (bSet) { 435 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
448 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; 436 else
449 } else { 437 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
450 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; 438
451 } 439 Repaint(&m_rtClient);
452 m_pOwner->Repaint(&m_pOwner->m_rtClient);
453 } 440 }
454 441
455 void CFWL_PushButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { 442 void IFWL_PushButton::OnLButtonDown(CFWL_MsgMouse* pMsg) {
456 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { 443 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
457 m_pOwner->SetFocus(TRUE); 444 SetFocus(TRUE);
458 } 445
459 m_pOwner->m_bBtnDown = TRUE; 446 m_bBtnDown = TRUE;
460 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; 447 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
461 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; 448 m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed;
462 m_pOwner->Repaint(&m_pOwner->m_rtClient); 449 Repaint(&m_rtClient);
463 } 450 }
464 451
465 void CFWL_PushButtonImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { 452 void IFWL_PushButton::OnLButtonUp(CFWL_MsgMouse* pMsg) {
466 m_pOwner->m_bBtnDown = FALSE; 453 m_bBtnDown = FALSE;
467 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { 454 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) {
468 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; 455 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
469 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; 456 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
470 } else { 457 } else {
471 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; 458 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered;
472 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; 459 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
473 } 460 }
474 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { 461 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) {
475 CFWL_EvtClick wmClick; 462 CFWL_EvtClick wmClick;
476 wmClick.m_pSrcTarget = m_pOwner; 463 wmClick.m_pSrcTarget = this;
477 m_pOwner->DispatchEvent(&wmClick); 464 DispatchEvent(&wmClick);
478 } 465 }
479 m_pOwner->Repaint(&m_pOwner->m_rtClient); 466 Repaint(&m_rtClient);
480 } 467 }
481 468
482 void CFWL_PushButtonImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { 469 void IFWL_PushButton::OnMouseMove(CFWL_MsgMouse* pMsg) {
483 FX_BOOL bRepaint = FALSE; 470 FX_BOOL bRepaint = FALSE;
484 if (m_pOwner->m_bBtnDown) { 471 if (m_bBtnDown) {
485 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { 472 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) {
486 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) { 473 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) {
487 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; 474 m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed;
488 bRepaint = TRUE; 475 bRepaint = TRUE;
489 } 476 }
490 if (m_pOwner->m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) { 477 if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) {
491 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; 478 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered;
492 bRepaint = TRUE; 479 bRepaint = TRUE;
493 } 480 }
494 } else { 481 } else {
495 if (m_pOwner->m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) { 482 if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) {
496 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; 483 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
497 bRepaint = TRUE; 484 bRepaint = TRUE;
498 } 485 }
499 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { 486 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) {
500 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; 487 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
501 bRepaint = TRUE; 488 bRepaint = TRUE;
502 } 489 }
503 } 490 }
504 } else { 491 } else {
505 if (!m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { 492 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy))
506 return; 493 return;
507 } 494 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) {
508 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { 495 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
509 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
510 bRepaint = TRUE; 496 bRepaint = TRUE;
511 } 497 }
512 } 498 }
513 if (bRepaint) { 499 if (bRepaint)
514 m_pOwner->Repaint(&m_pOwner->m_rtClient); 500 Repaint(&m_rtClient);
515 }
516 } 501 }
517 502
518 void CFWL_PushButtonImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { 503 void IFWL_PushButton::OnMouseLeave(CFWL_MsgMouse* pMsg) {
519 m_pOwner->m_bBtnDown = FALSE; 504 m_bBtnDown = FALSE;
520 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; 505 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered;
521 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; 506 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
522 m_pOwner->Repaint(&m_pOwner->m_rtClient); 507 Repaint(&m_rtClient);
523 } 508 }
524 509
525 void CFWL_PushButtonImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { 510 void IFWL_PushButton::OnKeyDown(CFWL_MsgKey* pMsg) {
526 if (pMsg->m_dwKeyCode == FWL_VKEY_Return) { 511 if (pMsg->m_dwKeyCode == FWL_VKEY_Return) {
527 CFWL_EvtMouse wmMouse; 512 CFWL_EvtMouse wmMouse;
528 wmMouse.m_pSrcTarget = m_pOwner; 513 wmMouse.m_pSrcTarget = this;
529 wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp; 514 wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp;
530 m_pOwner->DispatchEvent(&wmMouse); 515 DispatchEvent(&wmMouse);
531 CFWL_EvtClick wmClick; 516 CFWL_EvtClick wmClick;
532 wmClick.m_pSrcTarget = m_pOwner; 517 wmClick.m_pSrcTarget = this;
533 m_pOwner->DispatchEvent(&wmClick); 518 DispatchEvent(&wmClick);
534 return; 519 return;
535 } 520 }
536 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) { 521 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab)
537 return; 522 return;
538 } 523
539 m_pOwner->DispatchKeyEvent(pMsg); 524 DispatchKeyEvent(pMsg);
540 } 525 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/ifwl_pushbutton.h ('k') | xfa/fwl/core/ifwl_scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698