Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 m_muteButton.get(), | 724 m_muteButton.get(), |
| 725 m_volumeSlider.get(), | 725 m_volumeSlider.get(), |
| 726 m_toggleClosedCaptionsButton.get(), | 726 m_toggleClosedCaptionsButton.get(), |
| 727 m_castButton.get(), | 727 m_castButton.get(), |
| 728 m_currentTimeDisplay.get(), | 728 m_currentTimeDisplay.get(), |
| 729 m_durationDisplay.get(), | 729 m_durationDisplay.get(), |
| 730 }; | 730 }; |
| 731 | 731 |
| 732 int usedWidth = 0; | 732 int usedWidth = 0; |
| 733 | 733 |
| 734 // Assume that all controls require 48px, unless we can get the computed | 734 // Assume that all controls require 32px, unless we can get the computed |
| 735 // style for the play button. Since the play button or overflow is always | 735 // style for the play button. Since the play button or overflow is always |
| 736 // shown, one of the two buttons should be available the first time we're | 736 // shown, one of the two buttons should be available the first time we're |
| 737 // called after layout. This will | 737 // called after layout. This will |
| 738 // also be the first time we have m_panelWidth!=0, so it won't matter if | 738 // also be the first time we have m_panelWidth!=0, so it won't matter if |
| 739 // we get this wrong before that. | 739 // we get this wrong before that. |
| 740 int minimumWidth = 48; | 740 int minimumWidth = 32; |
| 741 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { | 741 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { |
| 742 const ComputedStyle* style = m_playButton->layoutObject()->style(); | 742 const ComputedStyle* style = m_playButton->layoutObject()->style(); |
| 743 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); | 743 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); |
| 744 } else if (m_overflowMenu->layoutObject() && m_overflowMenu->layoutObject()- >style()) { | 744 } else if (m_overflowMenu->layoutObject() && m_overflowMenu->layoutObject()- >style()) { |
| 745 const ComputedStyle* style = m_overflowMenu->layoutObject()->style(); | 745 const ComputedStyle* style = m_overflowMenu->layoutObject()->style(); |
| 746 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); | 746 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); |
| 747 } | 747 } |
| 748 | 748 |
| 749 // TODO(mlamouri): we need a more dynamic way to find out the width of an | |
| 750 // element. | |
| 751 int largeMinimumWidth = minimumWidth * 2; | |
|
liberato (no reviews please)
2016/09/27 16:33:53
is this enough on desktop? there is 18px margin o
mlamouri (slow - plz ping)
2016/09/29 13:00:39
Done.
| |
| 752 | |
| 749 if (!m_panelWidth) { | 753 if (!m_panelWidth) { |
| 750 // No layout yet -- hide everything, then make them show up later. | 754 // No layout yet -- hide everything, then make them show up later. |
| 751 // This prevents the wrong controls from being shown briefly | 755 // This prevents the wrong controls from being shown briefly |
| 752 // immediately after the first layout and paint, but before we have | 756 // immediately after the first layout and paint, but before we have |
| 753 // a chance to revise them. | 757 // a chance to revise them. |
| 754 for (MediaControlElement* element : elements) { | 758 for (MediaControlElement* element : elements) { |
| 755 if (element) | 759 if (element) |
| 756 element->setDoesFit(false); | 760 element->setDoesFit(false); |
| 757 } | 761 } |
| 758 return; | 762 return; |
| 759 } | 763 } |
| 760 | 764 |
| 761 // Insert an overflow menu. However, if we see that the overflow menu | 765 // Insert an overflow menu. However, if we see that the overflow menu |
| 762 // doesn't end up containing at least two elements, we will not display it | 766 // doesn't end up containing at least two elements, we will not display it |
| 763 // but instead make place for the first element that was dropped. | 767 // but instead make place for the first element that was dropped. |
| 764 m_overflowMenu->setDoesFit(true); | 768 m_overflowMenu->setDoesFit(true); |
| 765 m_overflowMenu->setIsWanted(true); | 769 m_overflowMenu->setIsWanted(true); |
| 766 usedWidth = minimumWidth; | 770 usedWidth = minimumWidth; |
| 767 | 771 |
| 768 std::list<MediaControlElement*> overflowElements; | 772 std::list<MediaControlElement*> overflowElements; |
| 769 MediaControlElement* firstDisplacedElement = nullptr; | 773 MediaControlElement* firstDisplacedElement = nullptr; |
| 770 // For each control that fits, enable it in order of decreasing priority. | 774 // For each control that fits, enable it in order of decreasing priority. |
| 771 bool droppedCastButton = false; | 775 bool droppedCastButton = false; |
| 772 for (MediaControlElement* element : elements) { | 776 for (MediaControlElement* element : elements) { |
| 773 if (!element) | 777 if (!element) |
| 774 continue; | 778 continue; |
| 779 int width = minimumWidth; | |
| 780 if ((element == m_timeline.get()) || (element == m_volumeSlider.get())) | |
| 781 width = largeMinimumWidth; | |
| 775 element->shouldShowButtonInOverflowMenu(false); | 782 element->shouldShowButtonInOverflowMenu(false); |
| 776 if (element->isWanted()) { | 783 if (element->isWanted()) { |
| 777 if (usedWidth + minimumWidth <= m_panelWidth) { | 784 if (usedWidth + width <= m_panelWidth) { |
| 778 element->setDoesFit(true); | 785 element->setDoesFit(true); |
| 779 usedWidth += minimumWidth; | 786 usedWidth += width; |
| 780 } else { | 787 } else { |
| 781 element->setDoesFit(false); | 788 element->setDoesFit(false); |
| 789 // TODO(mlamouri): we should probably no longer mark the cast | |
| 790 // button as dropped, it should appear in the overflow menu. | |
| 782 if (element == m_castButton.get()) | 791 if (element == m_castButton.get()) |
| 783 droppedCastButton = true; | 792 droppedCastButton = true; |
| 784 element->shouldShowButtonInOverflowMenu(true); | 793 element->shouldShowButtonInOverflowMenu(true); |
| 785 if (element->hasOverflowButton()) | 794 if (element->hasOverflowButton()) |
| 786 overflowElements.push_front(element); | 795 overflowElements.push_front(element); |
| 787 // We want a way to access the first media element that was | 796 // We want a way to access the first media element that was |
| 788 // removed. If we don't end up needing an overflow menu, we can | 797 // removed. If we don't end up needing an overflow menu, we can |
| 789 // use the space the overflow menu would have taken up to | 798 // use the space the overflow menu would have taken up to |
| 790 // instead display that media element. | 799 // instead display that media element. |
| 791 if (!element->hasOverflowButton() && !firstDisplacedElement) | 800 if (!element->hasOverflowButton() && !firstDisplacedElement) |
| 792 firstDisplacedElement = element; | 801 firstDisplacedElement = element; |
| 793 } | 802 } |
| 794 } | 803 } |
| 795 } | 804 } |
| 796 | 805 |
| 797 // If we don't have at least two overflow elements, we will not show the | 806 // If we don't have at least two overflow elements, we will not show the |
| 798 // overflow menu. | 807 // overflow menu. |
| 799 if (overflowElements.empty()) { | 808 if (overflowElements.empty()) { |
| 800 m_overflowMenu->setIsWanted(false); | 809 m_overflowMenu->setIsWanted(false); |
| 801 if (firstDisplacedElement) | 810 usedWidth -= minimumWidth; |
| 802 firstDisplacedElement->setDoesFit(true); | 811 if (firstDisplacedElement) { |
| 812 int width = minimumWidth; | |
| 813 if ((firstDisplacedElement == m_timeline.get()) || (firstDisplacedEl ement == m_volumeSlider.get())) | |
| 814 width = largeMinimumWidth; | |
| 815 if (usedWidth + width <= m_panelWidth) | |
| 816 firstDisplacedElement->setDoesFit(true); | |
| 817 } | |
| 803 } else if (overflowElements.size() == 1) { | 818 } else if (overflowElements.size() == 1) { |
| 819 LOG(INFO) << "set first element"; | |
|
liberato (no reviews please)
2016/09/27 16:33:53
:)
mlamouri (slow - plz ping)
2016/09/29 13:00:39
Done.
| |
| 804 m_overflowMenu->setIsWanted(false); | 820 m_overflowMenu->setIsWanted(false); |
| 805 overflowElements.front()->setDoesFit(true); | 821 overflowElements.front()->setDoesFit(true); |
| 806 } | 822 } |
| 807 | 823 |
| 808 // Special case for cast: if we want a cast button but dropped it, then | 824 // Special case for cast: if we want a cast button but dropped it, then |
| 809 // show the overlay cast button instead. | 825 // show the overlay cast button instead. |
| 810 if (m_castButton->isWanted()) { | 826 if (m_castButton->isWanted()) { |
| 811 if (droppedCastButton) | 827 if (droppedCastButton) |
| 812 m_overlayCastButton->tryShowOverlay(); | 828 m_overlayCastButton->tryShowOverlay(); |
| 813 else | 829 else |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 visitor->trace(m_enclosure); | 886 visitor->trace(m_enclosure); |
| 871 visitor->trace(m_textTrackList); | 887 visitor->trace(m_textTrackList); |
| 872 visitor->trace(m_overflowMenu); | 888 visitor->trace(m_overflowMenu); |
| 873 visitor->trace(m_overflowList); | 889 visitor->trace(m_overflowList); |
| 874 visitor->trace(m_castButton); | 890 visitor->trace(m_castButton); |
| 875 visitor->trace(m_overlayCastButton); | 891 visitor->trace(m_overlayCastButton); |
| 876 HTMLDivElement::trace(visitor); | 892 HTMLDivElement::trace(visitor); |
| 877 } | 893 } |
| 878 | 894 |
| 879 } // namespace blink | 895 } // namespace blink |
| OLD | NEW |