Element.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "../Common/TestsShell.h"
  29. #include <RmlUi/Core/Context.h>
  30. #include <RmlUi/Core/Element.h>
  31. #include <RmlUi/Core/ElementDocument.h>
  32. #include <doctest.h>
  33. using namespace Rml;
  34. static const String document_clone_rml = R"(
  35. <rml>
  36. <head>
  37. <title>Test</title>
  38. <link type="text/rcss" href="/assets/rml.rcss"/>
  39. <link type="text/rcss" href="/assets/invader.rcss"/>
  40. <style>
  41. body
  42. {
  43. left: 0;
  44. top: 0;
  45. right: 0;
  46. bottom: 0;
  47. }
  48. div {
  49. drag: clone;
  50. background: #ccc;
  51. height: 100px;
  52. }
  53. span {
  54. color: red;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <div>This is a <span>sample</span>.</div>
  60. </body>
  61. </rml>
  62. )";
  63. TEST_CASE("element.clone")
  64. {
  65. Context* context = TestsShell::GetContext();
  66. REQUIRE(context);
  67. ElementDocument* document = context->LoadDocumentFromMemory(document_clone_rml);
  68. REQUIRE(document);
  69. document->Show();
  70. context->Update();
  71. context->Render();
  72. TestsShell::RenderLoop();
  73. // Simulate input for mouse click and drag
  74. context->ProcessMouseMove(10, 10, 0);
  75. context->Update();
  76. context->Render();
  77. context->ProcessMouseButtonDown(0, 0);
  78. context->Update();
  79. context->Render();
  80. // This should initiate a drag clone.
  81. context->ProcessMouseMove(10, 11, 0);
  82. context->Update();
  83. context->Render();
  84. context->ProcessMouseButtonUp(0, 0);
  85. document->Close();
  86. TestsShell::ShutdownShell();
  87. }