-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20200 from brave/reading_list_panel_header
Added header to reading list panel
- Loading branch information
Showing
10 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+914 Bytes
app/theme/default_100_percent/brave/sidebar_reading_list_panel_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.9 KB
app/theme/default_200_percent/brave/sidebar_reading_list_panel_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
browser/ui/views/side_panel/brave_read_later_side_panel_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/views/side_panel/brave_read_later_side_panel_view.h" | ||
|
||
#include <memory> | ||
|
||
#include "brave/browser/ui/color/brave_color_id.h" | ||
#include "brave/grit/brave_generated_resources.h" | ||
#include "brave/grit/brave_theme_resources.h" | ||
#include "chrome/browser/ui/views/side_panel/read_later_side_panel_web_view.h" | ||
#include "chrome/browser/ui/views/side_panel/side_panel_content_proxy.h" | ||
#include "chrome/browser/ui/views/side_panel/side_panel_util.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/resource/resource_bundle.h" | ||
#include "ui/gfx/font_list.h" | ||
#include "ui/gfx/geometry/insets.h" | ||
#include "ui/views/background.h" | ||
#include "ui/views/controls/image_view.h" | ||
#include "ui/views/controls/label.h" | ||
#include "ui/views/controls/separator.h" | ||
#include "ui/views/layout/flex_layout.h" | ||
#include "ui/views/layout/layout_types.h" | ||
|
||
namespace { | ||
|
||
// Renders icon and title. | ||
class ReadLaterSidePanelHeaderView : public views::View { | ||
public: | ||
ReadLaterSidePanelHeaderView() { | ||
constexpr int kHeaderInteriorMargin = 16; | ||
SetLayoutManager(std::make_unique<views::FlexLayout>()) | ||
->SetOrientation(views::LayoutOrientation::kHorizontal) | ||
.SetInteriorMargin(gfx::Insets(kHeaderInteriorMargin)) | ||
.SetMainAxisAlignment(views::LayoutAlignment::kStart) | ||
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter); | ||
|
||
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | ||
auto* header_image = AddChildView( | ||
std::make_unique<views::ImageView>(ui::ImageModel::FromImageSkia( | ||
*rb.GetImageSkiaNamed(IDR_SIDEBAR_READING_LIST_PANEL_HEADER)))); | ||
constexpr int kSpacingBetweenHeaderImageAndLabel = 8; | ||
header_image->SetProperty( | ||
views::kMarginsKey, | ||
gfx::Insets::TLBR(0, 0, 0, kSpacingBetweenHeaderImageAndLabel)); | ||
header_image->SetProperty( | ||
views::kFlexBehaviorKey, | ||
views::FlexSpecification(views::MinimumFlexSizeRule::kPreferred, | ||
views::MaximumFlexSizeRule::kPreferred)); | ||
|
||
auto* header_label = | ||
AddChildView(std::make_unique<views::Label>(l10n_util::GetStringUTF16( | ||
IDS_SIDEBAR_READING_LIST_PANEL_HEADER_TITLE))); | ||
header_label->SetFontList(gfx::FontList("Poppins, Semi-Bold 16px")); | ||
header_label->SetEnabledColorId(kColorSidebarPanelHeaderTitle); | ||
header_label->SetProperty( | ||
views::kFlexBehaviorKey, | ||
views::FlexSpecification(views::MinimumFlexSizeRule::kPreferred, | ||
views::MaximumFlexSizeRule::kPreferred)); | ||
|
||
SetBackground( | ||
views::CreateThemedSolidBackground(kColorSidebarPanelHeaderBackground)); | ||
} | ||
|
||
~ReadLaterSidePanelHeaderView() override = default; | ||
ReadLaterSidePanelHeaderView(const ReadLaterSidePanelHeaderView&) = delete; | ||
ReadLaterSidePanelHeaderView& operator=(const ReadLaterSidePanelHeaderView&) = | ||
delete; | ||
}; | ||
|
||
} // namespace | ||
|
||
BraveReadLaterSidePanelView::BraveReadLaterSidePanelView( | ||
Browser* browser, | ||
base::RepeatingClosure close_cb) { | ||
SetLayoutManager(std::make_unique<views::FlexLayout>()) | ||
->SetOrientation(views::LayoutOrientation::kVertical); | ||
AddChildView(std::make_unique<ReadLaterSidePanelHeaderView>()); | ||
AddChildView(std::make_unique<views::Separator>()) | ||
->SetColorId(kColorSidebarPanelHeaderSeparator); | ||
auto* web_view = AddChildView( | ||
std::make_unique<ReadLaterSidePanelWebView>(browser, close_cb)); | ||
web_view->SetProperty( | ||
views::kFlexBehaviorKey, | ||
views::FlexSpecification(views::MinimumFlexSizeRule::kPreferred, | ||
views::MaximumFlexSizeRule::kUnbounded)); | ||
|
||
// Originally SidePanelEntry's Content was ReadLaterSidePanelWebView | ||
// and it's availability is set to true when SidePanelWebUIView::ShowUI() | ||
// and then proxy's availability callback is executed. | ||
// However, we use parent view(BraveReadLaterSidePanelView) to have | ||
// panel specific header view and this class becomes SidePanelEntry's Content. | ||
// To make this content available when SidePanelWebUIVew::ShowUI() is called, | ||
// this observes WebView's visibility because it's set as visible when | ||
// ShowUI() is called. | ||
// NOTE: If we use our own reading list page and it has loading spinner, maybe | ||
// we can set `true` here. | ||
SidePanelUtil::GetSidePanelContentProxy(this)->SetAvailable(false); | ||
observation_.Observe(web_view); | ||
} | ||
|
||
void BraveReadLaterSidePanelView::OnViewVisibilityChanged( | ||
views::View* observed_view, | ||
views::View* starting_view) { | ||
// Once it becomes available, stop observing becuase its availablity is | ||
// not changed from now on. | ||
if (observed_view->GetVisible()) { | ||
SidePanelUtil::GetSidePanelContentProxy(this)->SetAvailable(true); | ||
observation_.Reset(); | ||
} | ||
} | ||
|
||
BraveReadLaterSidePanelView::~BraveReadLaterSidePanelView() = default; |
34 changes: 34 additions & 0 deletions
34
browser/ui/views/side_panel/brave_read_later_side_panel_view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_VIEWS_SIDE_PANEL_BRAVE_READ_LATER_SIDE_PANEL_VIEW_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_SIDE_PANEL_BRAVE_READ_LATER_SIDE_PANEL_VIEW_H_ | ||
|
||
#include "base/functional/callback_forward.h" | ||
#include "base/scoped_observation.h" | ||
#include "ui/views/view.h" | ||
#include "ui/views/view_observer.h" | ||
|
||
class Browser; | ||
|
||
// Gives reading list specific header view with web view. | ||
class BraveReadLaterSidePanelView : public views::View, | ||
public views::ViewObserver { | ||
public: | ||
BraveReadLaterSidePanelView(Browser* browser, | ||
base::RepeatingClosure close_cb); | ||
~BraveReadLaterSidePanelView() override; | ||
BraveReadLaterSidePanelView(const BraveReadLaterSidePanelView&) = delete; | ||
BraveReadLaterSidePanelView& operator=(const BraveReadLaterSidePanelView&) = | ||
delete; | ||
|
||
private: | ||
void OnViewVisibilityChanged(views::View* observed_view, | ||
views::View* starting_view) override; | ||
|
||
base::ScopedObservation<views::View, views::ViewObserver> observation_{this}; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_VIEWS_SIDE_PANEL_BRAVE_READ_LATER_SIDE_PANEL_VIEW_H_ |
13 changes: 13 additions & 0 deletions
13
...rc/chrome/browser/ui/views/side_panel/reading_list/reading_list_side_panel_coordinator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/browser/ui/views/side_panel/brave_read_later_side_panel_view.h" | ||
#include "chrome/browser/ui/views/side_panel/read_later_side_panel_web_view.h" | ||
|
||
#define ReadLaterSidePanelWebView BraveReadLaterSidePanelView | ||
|
||
#include "src/chrome/browser/ui/views/side_panel/reading_list/reading_list_side_panel_coordinator.cc" | ||
|
||
#undef ReadLaterSidePanelWebView |