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

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

Issue 2489013002: Continue cleaning IFWL classes (Closed)
Patch Set: Review updates 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
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_spinbutton.h" 7 #include "xfa/fwl/core/ifwl_spinbutton.h"
8 8
9 #include "third_party/base/ptr_util.h" 9 #include "third_party/base/ptr_util.h"
10 #include "xfa/fwl/core/cfwl_message.h" 10 #include "xfa/fwl/core/cfwl_message.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); 103 IFWL_ThemeProvider* pTheme = GetAvailableTheme();
104 if (HasBorder()) 104 if (HasBorder())
105 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); 105 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix);
106 if (HasEdge()) 106 if (HasEdge())
107 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); 107 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix);
108 108
109 DrawUpButton(pGraphics, pTheme, pMatrix); 109 DrawUpButton(pGraphics, pTheme, pMatrix);
110 DrawDownButton(pGraphics, pTheme, pMatrix); 110 DrawDownButton(pGraphics, pTheme, pMatrix);
111 } 111 }
112 112
113 FWL_Error IFWL_SpinButton::EnableButton(bool bEnable, bool bUp) { 113 void IFWL_SpinButton::EnableButton(bool bEnable, bool bUp) {
114 if (bUp) 114 if (bUp)
115 m_dwUpState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; 115 m_dwUpState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled;
116 else 116 else
117 m_dwDnState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; 117 m_dwDnState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled;
118
119 return FWL_Error::Succeeded;
120 } 118 }
121 119
122 bool IFWL_SpinButton::IsButtonEnable(bool bUp) { 120 bool IFWL_SpinButton::IsButtonEnabled(bool bUp) {
123 if (bUp) 121 if (bUp)
124 return (m_dwUpState != CFWL_PartState_Disabled); 122 return (m_dwUpState != CFWL_PartState_Disabled);
125 return (m_dwDnState != CFWL_PartState_Disabled); 123 return (m_dwDnState != CFWL_PartState_Disabled);
126 } 124 }
127 125
128 void IFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, 126 void IFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics,
129 IFWL_ThemeProvider* pTheme, 127 IFWL_ThemeProvider* pTheme,
130 const CFX_Matrix* pMatrix) { 128 const CFX_Matrix* pMatrix) {
131 CFWL_ThemeBackground params; 129 CFWL_ThemeBackground params;
132 params.m_pWidget = this; 130 params.m_pWidget = this;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 214 }
217 215
218 void IFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { 216 void IFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) {
219 m_bLButtonDwn = true; 217 m_bLButtonDwn = true;
220 SetGrab(true); 218 SetGrab(true);
221 SetFocus(true); 219 SetFocus(true);
222 if (!m_pProperties->m_pDataProvider) 220 if (!m_pProperties->m_pDataProvider)
223 return; 221 return;
224 222
225 bool bUpPress = 223 bool bUpPress =
226 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnable(true)); 224 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(true));
227 bool bDnPress = 225 bool bDnPress =
228 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnable(false)); 226 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(false));
229 if (!bUpPress && !bDnPress) 227 if (!bUpPress && !bDnPress)
230 return; 228 return;
231 if (bUpPress) { 229 if (bUpPress) {
232 m_iButtonIndex = 0; 230 m_iButtonIndex = 0;
233 m_dwUpState = CFWL_PartState_Pressed; 231 m_dwUpState = CFWL_PartState_Pressed;
234 } 232 }
235 if (bDnPress) { 233 if (bDnPress) {
236 m_iButtonIndex = 1; 234 m_iButtonIndex = 1;
237 m_dwDnState = CFWL_PartState_Pressed; 235 m_dwDnState = CFWL_PartState_Pressed;
238 } 236 }
(...skipping 11 matching lines...) Expand all
250 248
251 m_bLButtonDwn = false; 249 m_bLButtonDwn = false;
252 SetGrab(false); 250 SetGrab(false);
253 SetFocus(false); 251 SetFocus(false);
254 if (m_pTimerInfo) { 252 if (m_pTimerInfo) {
255 m_pTimerInfo->StopTimer(); 253 m_pTimerInfo->StopTimer();
256 m_pTimerInfo = nullptr; 254 m_pTimerInfo = nullptr;
257 } 255 }
258 bool bRepaint = false; 256 bool bRepaint = false;
259 CFX_RectF rtInvalidate; 257 CFX_RectF rtInvalidate;
260 if (m_dwUpState == CFWL_PartState_Pressed && IsButtonEnable(true)) { 258 if (m_dwUpState == CFWL_PartState_Pressed && IsButtonEnabled(true)) {
261 m_dwUpState = CFWL_PartState_Normal; 259 m_dwUpState = CFWL_PartState_Normal;
262 bRepaint = true; 260 bRepaint = true;
263 rtInvalidate = m_rtUpButton; 261 rtInvalidate = m_rtUpButton;
264 } else if (m_dwDnState == CFWL_PartState_Pressed && IsButtonEnable(false)) { 262 } else if (m_dwDnState == CFWL_PartState_Pressed && IsButtonEnabled(false)) {
265 m_dwDnState = CFWL_PartState_Normal; 263 m_dwDnState = CFWL_PartState_Normal;
266 bRepaint = true; 264 bRepaint = true;
267 rtInvalidate = m_rtDnButton; 265 rtInvalidate = m_rtDnButton;
268 } 266 }
269 if (bRepaint) 267 if (bRepaint)
270 Repaint(&rtInvalidate); 268 Repaint(&rtInvalidate);
271 } 269 }
272 270
273 void IFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { 271 void IFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) {
274 if (!m_pProperties->m_pDataProvider) 272 if (!m_pProperties->m_pDataProvider)
275 return; 273 return;
276 if (m_bLButtonDwn) 274 if (m_bLButtonDwn)
277 return; 275 return;
278 276
279 bool bRepaint = false; 277 bool bRepaint = false;
280 CFX_RectF rtInvlidate; 278 CFX_RectF rtInvlidate;
281 rtInvlidate.Reset(); 279 rtInvlidate.Reset();
282 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { 280 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) {
283 if (IsButtonEnable(true)) { 281 if (IsButtonEnabled(true)) {
284 if (m_dwUpState == CFWL_PartState_Hovered) { 282 if (m_dwUpState == CFWL_PartState_Hovered) {
285 m_dwUpState = CFWL_PartState_Hovered; 283 m_dwUpState = CFWL_PartState_Hovered;
286 bRepaint = true; 284 bRepaint = true;
287 rtInvlidate = m_rtUpButton; 285 rtInvlidate = m_rtUpButton;
288 } 286 }
289 if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnable(false)) { 287 if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) {
290 m_dwDnState = CFWL_PartState_Normal; 288 m_dwDnState = CFWL_PartState_Normal;
291 if (bRepaint) 289 if (bRepaint)
292 rtInvlidate.Union(m_rtDnButton); 290 rtInvlidate.Union(m_rtDnButton);
293 else 291 else
294 rtInvlidate = m_rtDnButton; 292 rtInvlidate = m_rtDnButton;
295 293
296 bRepaint = true; 294 bRepaint = true;
297 } 295 }
298 } 296 }
299 if (!IsButtonEnable(false)) 297 if (!IsButtonEnabled(false))
300 EnableButton(false, false); 298 EnableButton(false, false);
301 299
302 } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { 300 } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) {
303 if (IsButtonEnable(false)) { 301 if (IsButtonEnabled(false)) {
304 if (m_dwDnState != CFWL_PartState_Hovered) { 302 if (m_dwDnState != CFWL_PartState_Hovered) {
305 m_dwDnState = CFWL_PartState_Hovered; 303 m_dwDnState = CFWL_PartState_Hovered;
306 bRepaint = true; 304 bRepaint = true;
307 rtInvlidate = m_rtDnButton; 305 rtInvlidate = m_rtDnButton;
308 } 306 }
309 if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnable(true)) { 307 if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) {
310 m_dwUpState = CFWL_PartState_Normal; 308 m_dwUpState = CFWL_PartState_Normal;
311 if (bRepaint) 309 if (bRepaint)
312 rtInvlidate.Union(m_rtUpButton); 310 rtInvlidate.Union(m_rtUpButton);
313 else 311 else
314 rtInvlidate = m_rtUpButton; 312 rtInvlidate = m_rtUpButton;
315 bRepaint = true; 313 bRepaint = true;
316 } 314 }
317 } 315 }
318 } else if (m_dwUpState != CFWL_PartState_Normal || 316 } else if (m_dwUpState != CFWL_PartState_Normal ||
319 m_dwDnState != CFWL_PartState_Normal) { 317 m_dwDnState != CFWL_PartState_Normal) {
(...skipping 12 matching lines...) Expand all
332 bRepaint = true; 330 bRepaint = true;
333 } 331 }
334 } 332 }
335 if (bRepaint) 333 if (bRepaint)
336 Repaint(&rtInvlidate); 334 Repaint(&rtInvlidate);
337 } 335 }
338 336
339 void IFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { 337 void IFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) {
340 if (!pMsg) 338 if (!pMsg)
341 return; 339 return;
342 if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnable(true)) 340 if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true))
343 m_dwUpState = CFWL_PartState_Normal; 341 m_dwUpState = CFWL_PartState_Normal;
344 if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnable(false)) 342 if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false))
345 m_dwDnState = CFWL_PartState_Normal; 343 m_dwDnState = CFWL_PartState_Normal;
346 344
347 Repaint(&m_rtClient); 345 Repaint(&m_rtClient);
348 } 346 }
349 347
350 void IFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { 348 void IFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) {
351 if (!m_pProperties->m_pDataProvider) 349 if (!m_pProperties->m_pDataProvider)
352 return; 350 return;
353 351
354 bool bUp = 352 bool bUp =
355 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; 353 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left;
356 bool bDown = 354 bool bDown =
357 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; 355 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right;
358 if (!bUp && !bDown) 356 if (!bUp && !bDown)
359 return; 357 return;
360 358
361 bool bUpEnable = IsButtonEnable(true); 359 bool bUpEnable = IsButtonEnabled(true);
362 bool bDownEnable = IsButtonEnable(false); 360 bool bDownEnable = IsButtonEnabled(false);
363 if (!bUpEnable && !bDownEnable) 361 if (!bUpEnable && !bDownEnable)
364 return; 362 return;
365 363
366 CFWL_EvtSpbClick wmPosChanged; 364 CFWL_EvtSpbClick wmPosChanged;
367 wmPosChanged.m_pSrcTarget = this; 365 wmPosChanged.m_pSrcTarget = this;
368 wmPosChanged.m_bUp = bUpEnable; 366 wmPosChanged.m_bUp = bUpEnable;
369 DispatchEvent(&wmPosChanged); 367 DispatchEvent(&wmPosChanged);
370 Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); 368 Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton);
371 } 369 }
372 370
373 IFWL_SpinButton::Timer::Timer(IFWL_SpinButton* pToolTip) 371 IFWL_SpinButton::Timer::Timer(IFWL_SpinButton* pToolTip)
374 : IFWL_Timer(pToolTip) {} 372 : IFWL_Timer(pToolTip) {}
375 373
376 void IFWL_SpinButton::Timer::Run(IFWL_TimerInfo* pTimerInfo) { 374 void IFWL_SpinButton::Timer::Run(IFWL_TimerInfo* pTimerInfo) {
377 IFWL_SpinButton* pButton = static_cast<IFWL_SpinButton*>(m_pWidget); 375 IFWL_SpinButton* pButton = static_cast<IFWL_SpinButton*>(m_pWidget);
378 376
379 if (!pButton->m_pTimerInfo) 377 if (!pButton->m_pTimerInfo)
380 return; 378 return;
381 379
382 CFWL_EvtSpbClick wmPosChanged; 380 CFWL_EvtSpbClick wmPosChanged;
383 wmPosChanged.m_pSrcTarget = pButton; 381 wmPosChanged.m_pSrcTarget = pButton;
384 wmPosChanged.m_bUp = pButton->m_iButtonIndex == 0; 382 wmPosChanged.m_bUp = pButton->m_iButtonIndex == 0;
385 pButton->DispatchEvent(&wmPosChanged); 383 pButton->DispatchEvent(&wmPosChanged);
386 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698